• Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in AttributeError: 'str' object has no attribute 'keys'

    @slavi Yes, you need an incremental json parser. By googling a few minutes, I found [ijson](https://pypi.python.org/pypi/ijson/) and its mother [yajl-py](http://pykler.github.io/yajl-py/). There may be others. @saran_1 Using an incremental json parser, …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in AttributeError: 'str' object has no attribute 'keys'

    Can you write an example json file with repeated keys in subobject and your expected output ?
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in AttributeError: 'str' object has no attribute 'keys'

    I mean import csv import json import sys def hook(obj): return obj def flatten(obj): for k, v in obj: if isinstance(v, list): yield from flatten(v) else: yield k, v if …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in AttributeError: 'str' object has no attribute 'keys'

    Can you explain what you mean by scalable here ? Do you want to apply this to a file having a very large number of keys ? Does it make …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in AttributeError: 'str' object has no attribute 'keys'

    I think you should definitely separate read and write. Start with a function that reads the json file and generates tuples such as ('Fee', 5, '1/1/0001 12:00:00 AM') Use the …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Polynomial functions stores

    It looks like homework. Did you try to add the polynomials in a python console ?
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Python script dumps Dyre malware configurations

    Interesting. It can be improved by using the standard modules argparse for command line parsing and subprocess to get output and error from called commands.
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in A ticker for long messages (Python/Tkinter)

    Once the text item is created, you can obtain a bounding box with `canvas.bbox(item=text)`, or something similar.
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Error too many loops

    Nor here (QupZilla in linux)
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Python implementations of markdown parsers that can produce HTML

    In order to see the source code, install the markdown or markdown2 module first, then visit the folder named markdown or markdown2. You can type in python >>> import markdown …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Python implementations of markdown parsers that can produce HTML

    Hm, you want to understand some basic things in programming, but the task of converting markdown to html is not such a basic thing. I would recommend it only to …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Command Help

    On my system, I installed the hh command from [Click Here](https://github.com/dvorka/hstr) (shell history suggest box). I can navigate history with the hh command and remove specific entries with the del …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Command Help

    These commands remain dangerous even after they've been used, because they remain in your shell history, with a risk of being recalled mistakenly, for example a ^r in a bash …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Command Help

    I would say `rm -rf *`.
  • Member Avatar for Gribouillis
    Gribouillis

    Gave Reputation to tobyITguy in Newbie Alert!

    Hi, I'm into php, C#, html, CSS and networking. Maybe alittle other stuff. I hope i'd be of help here. Im joining from Nigeria.
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in speed

    Your program could generate a random plate. The rules for the UK are described here [Click Here](https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_the_United_Kingdom,_Crown_dependencies_and_overseas_territories#Current_system). A first way to choose randomly is to have a list and use …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in speed

    If this is a question in the python programming forum, you could start reformulating the problem by introducing your program. What should your program do ? How will it read …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Need help in python snippet

    The code finds the lines containing the word `'python'` in the file named `'history'`. The search function yields the line containing that word and a deque of at most five …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in python repeat timer with gps

    I've always found the threading module easier when Condition instances are used. Here is a periodic timer implemented with a condition: from __future__ import print_function import datetime as dt import …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in change the 12 hour time in object

    > how i can call the file foo.py when i'm using the goleft function It's not the question. I still don't understand why you say that the code doesn't work. …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in change the 12 hour time in object

    All right, then create a file foo.py with the following code import datetime getTime1 = "01:00PM" t = datetime.datetime.strptime(getTime1, "%I:%M%p") + datetime.timedelta(days=36524) time_half_hour_before = (t - datetime.timedelta(minutes=30)).strftime("%I:%M%p") print time_half_hour_before Then …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in change the 12 hour time in object

    Why don't you upgrade to 2.7 ?
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in change the 12 hour time in object

    Can you import datetime ?
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in change the 12 hour time in object

    what does the exception traceback print ?
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in change the 12 hour time in object

    My code works >>> import datetime >>> getTime1 = "01:00PM" >>> t = datetime.datetime.strptime(getTime1, "%I:%M%p") + datetime.timedelta(days=36524) >>> time_half_hour_before = (t - datetime.timedelta(minutes=30)).strftime("%I:%M%p") >>> print time_half_hour_before 12:30PM you must be …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in change the 12 hour time in object

    You must add something because a datetime without a date gives you a datetime on the first of january 1900. There will be an error if you try to strftime …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in change the 12 hour time in object

    You can use the datetime module for these calculations. According to this module however, 12:00PM is at noon and 12:00AM is at midnight: >>> import datetime as dt >>> fm …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in how to use an Incrimental value in a generator?

    Unfortunately `v is int or long` means (v is int) or long It is always True because `bool(long`) is True. If you want to test if a value is an …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in how to use an Incrimental value in a generator?

    `bit_length()` is [documented](https://docs.python.org/3/library/stdtypes.html?highlight=bit_length#int.bit_length) in python 3. It has been backported to 2.7. Edit: it is actually also [documented in 2.7](https://docs.python.org/2/library/stdtypes.html?highlight=bit_length#int.bit_length). Edit: in python 2, `t.__class__ in (int, long)` would be …
  • Member Avatar for Gribouillis
    Gribouillis

    Gave Reputation to blud in Server migration complete

    Spell checker should now be resolved.
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Writing output into file

    Here is a way. I replaced all the print statements by calls to a function `printout()`. This function is built by using the `print_function` feature which makes python 2 look …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in raw_input and input in python 2.7

    If you input `[z * 5 for z in range(2, 10, 2)]`, it does not interfere.
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Server migration complete

    awesome!
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Star expression in for loop

    I think it works only with recent versions of python. For me, it works with python 3.4 but not with 2.7. Edit: you can write for rec in records: tag, …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in get function name on definition

    > decorators only work on function call, not on definition On the contrary, the decorator is called once, immediately after the function's definition >>> def deco(f): ... print f.__name__, 'is …
  • Member Avatar for Gribouillis
    Gribouillis

    Gave Reputation to Schol-R-LEA in get function name on definition

    > basically, what I want to do is add a function name to an outside reference in a safe sys.modules reference without copying the name... Have you considered writing a …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in raw_input and input in python 2.7

    Between the `raw_input()` and your printing `x`, there was an `input()`. This is where `x` was modified. About the dangers of `input()`, the point is that when a program writes …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in raw_input and input in python 2.7

    When `[x * 3 for x in range(2, 10, 2)]` is evaluated as a result of the input function, the variable `x` takes the values `2, 4, 6, 8`. When …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in how to use an Incrimental value in a generator?

    Here is my solution def field(template, value): res = 0 for t, v in zip(template, value)[::-1]: if t.__class__ is int: t = t.bit_length() else: t = int(t) res = (res …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in how to use an Incrimental value in a generator?

    Now I don't understand how the 1 3 4 become 0 1 8. Can you explain the connection between the two ?
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in how to use an Incrimental value in a generator?

    > a way to R-shift Value by the binary size of the data field I don't understand what you want to do. What is the *binary size of the data …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in fa = eval(Evaluar.funcion, {"__builtins__":None}, Evaluar.dicc_seguro) Fi

    We don't know which string you are evaluating; can you add raise RuntimeError(repr(Evaluar.funcion)) immediately before `fa = eval(...` and post the error output ?
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Correlate swingtime events with my existing users model.

    You could add a `user_event` table which rows would contain a rowid and 2 foreign keys.
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Correlate swingtime events with my existing users model.

    It is the first time I see this swingtime module, so I may be wrong, but I'm pessimistic here :)
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Correlate swingtime events with my existing users model.

    The documentation appears to live [here](http://swingtime.readthedocs.org/en/latest/index.html). I think you want something impossible. There is nothing about allowing a foreign key in an event (apart from the event type). The only …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in help in this proyect

    I'm afraid the indention didn't make it through the web editor. The best way to indent python code is with 4 space characters such as in if x == 0: …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Problem with loops searching for the information in the database

    This code is very difficult to understand. The first healthiness rule is that if a variable name is set in a loop condition, such as `pos_X` or `prog_id` in for …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Timing five isprime functions (Python)

    @slate I already saw such primality tests. Your code lacks a good reference to the mathematical algorithm used. It would be easier to understand the way it works with the …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Doubt in python call

    > If I use , in the place of +''+ **It gave this** You need to be precise. The output you are showing separates every arguments with a comma. Where …
  • Member Avatar for Gribouillis
    Gribouillis

    Replied To a Post in Doubt in python call

    Replace `+''+` with `,`. Why didn't you use `next(iter(...))` as I told you ?

The End.