How do I perform a random event in Python by picking a random variable?
Let's say I have to variables, dog and cat. Dog = 5, and cat = 3. How would I tell Python to pick one of these variables by random and print it to the screen? ...
Let's say I have to variables, dog and cat. Dog = 5, and cat = 3. How would I tell Python to pick one of these variables by random and print it to the screen? ...
Can I give the same name for different Models in different apps? and What conflicts can happen? After I have a try.. I got this Error: Error: One or more models did not validate: playlist.playlist: Accessor for field 'user' clashes with related field 'User.playlist_set'. Add a related_name argument to the definition for 'user'. audio_p...
I am using the output streams from the io module and writing to files. I want to be able to detect when I have written 1G of data to a file and then start writing to a second file. I can't seem to figure out how to determine how much data I have written to the file. Is there something easy built in to io? Or might I have to count the by...
I'm trying to make buildout config that installs psycopg2 egg and postgres from source if needed: parts = ... postgre psycopg2 ... [postgre] recipe = hexagonit.recipe.cmmi url = ftp://ftp3.ua.postgresql.org/pub/mirrors/postgresql/source/v9.0.0/postgresql-9.0.0.tar.gz configure-options = --without-readline [psycopg2...
Hi all, Apparently this is almost a duplicate of "Bad pipe filedescriptor when reading from stdin in python - Stack Overflow"; however, I believe this case is slightly more complicated (and it is not Windows specific, as the conclusion of that thread was). I'm currently trying to experiment with a simple script in Python: I'd like to...
I'm converting color values to string values, however when I get 0, the string is too short and I have to manually add "00" after it. Whats the most elegant way to solve this issue in Python ? print "#" + str(self.R) + str(self.G) + str(self.B) if self.R is 0 then I get a too short string. ...
What signal can I catch to detect when a column changes size in a gtk.TreeView? I can't seem to find it in the docs. ...
Python 2.7 under Windows: How can we control the position of Tkinter's common dialogs? Here's what we've discovered: Certain common dialogs always open up relative to their parent window Certain common dialogs always open up centered on the user's desktop All common dialogs appear to ignore the optional parent= parameter Questions: ...
Which framework has the most mature, flexible, intergrated, centralized and easy-to-use plugins/extension system. My main requirements are: a centralized system/repository where i could find a extension i need no need to make changes in the source code, the plugin should be easily enabled and disabled large plugin/extension database ...
My professor has given me an assignment on Pay roll system in python. There's one feature of printing Employees: All Employees Print by Attributes Print by Id Print by Name Print by Designation Print by Salary Print less than (<) Print greater than (>) ... all possible conditions Print by Depart...
I'm playing with Python callable. Basically you can define a python class and implement __call__ method to make the instance of this class callable. e.g., class AwesomeFunction(object): def __call__(self, a, b): return a+b Module inspect has a function getargspec, which gives you the argument specification of a function. H...
What is the best way to pack up an IronPython application for deployment? After scouring the web the best thing I've come up with (and what I'm currently doing) is using clr.CompileModules() to glue together my entire project's .py files into one .dll, and then having a single run.py do this to run the dll: import clr clr.AddReference(...
I'd like to build a "feed" for recent activity related to a specific section of my site. I haven't used memcache before, but I'm thinking of something like this: When a new piece of information is submitted to the site, assign a unique key to it and also add it to memcache. Add this key to the end of an existing list in memcache, so i...
Hey all, My current web host allows for up to 25 processes running at once. From what I can figure, Python scripts take up a spot in processes, but PHP doesn't? I get a 500 error if more than 25 processes are running at once (unlikely, but still a hassle), so I was wondering if it would be easier on the server if I were to port my sit...
I am writing a small diagram drawing application (similar to Graphviz in spirit), and need a GUI library that would allow me to embed a canvas capable of drawing anti-aliased lines and text. I want to have a text editor in one half of the window to edit the diagram code and a (perhaps live) preview pane in the other. Right now I have th...
I wouldn't call myself programmer, but I've started learning Python recently and really enjoy it. I mainly use it for small tasks so far - scripting, text processing, KML generation and ArcGIS. From my experience with R (working with excellent Notepad++ and NppToR combo) I usually try to work with my scripts line by line (or region by ...
I made a c extension out of a python script that was fairly labour intensive. The code itself is well tested and simple. The c extension is called with a few large lists, and it then performs some clever arithmetic and returns a few new lists. The c extension is 100% self sufficient, it doesn't use any other c functions nor does it use a...
Is it possible to run cprofile on a mult-threaded python program that forks itself into a daemon process? I know you can make it work on multi thread, but I haven't seen anything on profiling a daemon. ...
I'mm writing gtk code. I often have short callbacks that don't need to be closures, as they are passed all the parameters they need. For example, I have this in a loop when creating some gtk.TreeViewColumns: def widthChanged(MAINCOL, SPEC, SUBCOL, expandable): if expandable: return w = MAINCOL.get_width() SUBCOL.set_fixed_wi...
Does anyone know of a working and well documented implementation of a daemon using python? Please post a link here if you know of a project that fits these two requirements. ...