I have an indented text file that will be used to build a tree. Each line represents a node, and indents represent depth as well as node the current node is a child of. For example, a file might look like ROOT Node1 Node2 Node3 Node4 Node5 Node6 Which indicates that ROOT contains three children: 1, 5, and 6, …
Tag: python
django import error – No module named core.management
Ok, I see plenty of these errors around. I have tried everything I know to do and have yet to figure this out. I am working on a development server running python 2.5 and Django 1.3. Django 1.3 was installed using python setup.py install after unpacking the tar.gz download. All works well, I seldom have the n…
generate video pixel by pixel, programmatically
I’d like to generate an animation pixel by pixel programmatically. Preferably in Hi-Def, in Python or in Ruby. I thought about using PIL to make each frame and then convert the frames into video. Is there a better way to do this? EDIT: Clarification, this is 2D and I need the pixels to be precise. EDITE…
Python – Unflatten dict
I have this multi-dimensional dict: And written simple function to flatten that dict: After call this function with dict a i get in result: Now, after making few instructions on this flattened dict i need to build new, multi-dimensional dict from that flattened. Example: The only problem I have is that i do n…
How do I get the current time in milliseconds in Python?
How do I get the current time in milliseconds in Python? Answer Using time.time(): Then:
Python equivalent for MySQL’s IFNULL
Is there a function in Python that checks if the returned value is None and if it is, allows you to set it to another value like the IFNULL function in MySQL? Answer Not really, since you can’t rebind arguments. or
Should I return an empty dict instead of None?
I have a method that currently returns None or a dict. The caller currently has to check for the existence of two keys to decide what kind of object was returned. Because result can be None, I’m thinking of returning an empty dict instead, so the caller does not need to check for that. What do you think…
function is not defined error in Python
I am trying to define a basic function in python but I always get the following error when I run a simple test program; Here is the code I am using for this function; UPDATE: I have the script called pyth.py open, and then I am typing in pyth_test(1,2) in the interpreter when it gives the error. Thanks for th…
how to insert some text in all django context using django middleware
this my middleware code : this is the settings.py: and the view is : the html is : but it not show {{ss}}: so how do i show : how to insert some text in all django context using django middleware, so that i cant use to insert the text everytime , thanks Answer To meet your initial goal, I
decorating decorators: try to get my head around understanding it
I’m trying to understand how to decorate decorators, and wanted to try out the following: Let’s say I have two decorators and apply them to the function hello(): Then I have to start adding other decorators for other functions, but in general the @wrap decorator will “wrap all of them”…