python

Django Model set foreign key to a field of another Model

Is there any way to set a foreign key in django to a field of another model? For example, imagine I have a ValidationRule object. And I want the rule to define what field in another model is to be validated (as well as some other information, such as whether it can be null, a data-type, range, etc.) Is there a way to store this field-...

Replace html entities with the corresponding utf-8 characters in Python 2.6

I have a html text like this: &lt;xml ... &gt; and I want to convert it to something readable: <xml ...> Any easy (and fast) way to do it in Python? ...

mercurial + OSX == fail? hg log abort: Is a directory

$ mkdir foo $ cd foo $ hg init . $ hg log abort: Is a directory $ hg history abort: Is a directory Darwin Host.local 9.6.1 Darwin Kernel Version 9.6.1: Wed Dec 10 10:38:33 PST 2008; root:xnu-1228.9.75~3/RELEASE_I386 i386 $ hg --version Mercurial Distributed SCM (version 1.2.1) $ python --version Python 2.5.4 (all installed via macpo...

wxPython: Making a fixed-height panel

I have a wx.Frame, in which I have a vertical BoxSizer with two items, a TextCtrl and a custom widget. I want the custom widget to have a fixed pixel height, while the TextCtrl will expand normally to fill the window. What should I do? ...

Python/wxPython: Doing work continuously in the background

I'm making a program for running simulations in Python, with a wxPython interface. In the program, you can create a simulation, and the program renders (=calculates) it for you. Rendering can be very time-consuming sometimes. When the user starts a simulation, and defines an initial state, I want the program to render the simulation con...

Try/Catch in Python

When you just want to do a try catch without handling the exception, how do you do it in Python? try : shutil.rmtree ( path ) except : pass ...

draw text with GLUT / OpenGL in Python

Hey, I m drawing text with OpenGL in Python. It all works ok, however the font is really bad. If I make it thick the letters start to look very occurred (especially the ones which are round like 'o' or 'g'. For the purpose of my program it must be thick. Is there any font I could use which does not look so bad when thickened, or is ther...

How can I get useful information from flash swf files?

I'm doing some crawling with Python, and would like to be able to identify (however imperfectly) the flash I come across - is it a video, an ad, a game, or whatever. I assume I would have to decompile the swf, which seems doable. But what sort of processing would I do with the decompiled Actionscript to figure out what it's purpose is? ...

Pygame Invalid Syntax I just can't figure out.

I've been following a tutorial "McGugan - Beginning Game Development with Python and Pygame (Apress, 2007)" and in the code at around chapter five involving object movement I keep getting invalid syntax alerts on '-' being used in the code. It isn't up to date but I would've thought a subtract wouldn't be changed in any updates due to it...

What's easiest way to get Python script output on the web?

I have a python script that runs continuously. It outputs 2 lines of info every 30 seconds. I'd like to be able to view this output on the web. In particular, I'd like the site to auto-update (add the new output at the top of the page/site every 30 seconds without having to refresh the page). I understand I can do this with javascrip...

Is there a way to get all the directories but not files in a directory in Python?

This link is using a custom method, but I just wanna see if there is a single method to do it in Python 2.6? ...

Learning Web Development-Choosing a Language and Framework

This is a subjective question and let me make it clear that I AM NOT asking for what the best language is. That being said, I want to do web development. I want to create sites around various topics, some for myself and some to sell and also do freelance down the road. I would also like to be able to create applications (RIAish and We...

Showing data in a GUI where the data comes from an outside source

I'm kind of lost on how to approach this problem, I'd like to write a GUI ideally using Tkinter with python, but I initially started with Qt and found that the problem extends either with all GUI frameworks or my limited understanding. The data in this case is coming from a named pipe, and I'd like to display whatever comes through the ...

Resetting the main GUI window

I just want the equivalent of closing and reopening my main program. I want to invoke it when a "new"-like option from a drop-down menu is clicked on. Something like calling root.destroy() and then re-initiating the mainloop. How can I get this done? ...

Multiprocessing or Multithreading?

I'm making a program for running simulations in Python, with a wxPython interface. In the program, you can create a simulation, and the program renders (=calculates) it for you. Rendering can be very time-consuming sometimes. When the user starts a simulation, and defines an initial state, I want the program to render the simulation con...

Serving static files with mod_wsgi and Django

I have a django application using mod_python, fairly typical configuration except that media files are being served by a (I know, not recommended) 'media' directory in the document root. I would like to test and maybe deploy with mod_wsgi but I cannot figure out how to create something simple to serve static files. mod_python allows th...

Get Tk winfo_rgb() without having a window instantiated

I know I can call Tkinter.Tk().winfo_rgb(color) to get a tuple of values that represent the named color. for instance Tkinter.Tk().winfo_rgb("red") returns (65535, 0, 0) The problem is it also opens a window. I was hoping to abstract some color calculations into a generic color class, and handle whether or not the class was instantiat...

Python HTTP server that supports chunked encoding?

I'm looking for a well-supported multithreaded Python HTTP server that supports chunked encoding replies. (I.e. "Transfer-Encoding: chunked" on responses). What's the best HTTP server base to start with for this purpose? ...

Django Model: Returning username from currently logged in user

I'm working on a Django app for hosting media (specifically audio and images). I have image galleries and photos separate in my model, and have them linked with a ForeignKey (not sure if that's correct, but still learning). What I need is for the Album class's __unicode__ to return the album owner's username. class Album(models.Model): ...

HTML Rich Textbox

I'm writing a web-app using Python and Pylons. I need a textbox that is rich (ie, provides the ability to bold/underline/add bullets..etc...). Does anyone know a library or widget I can use? It doesn't have to be Python/Pylons specific, as it can be a Javascript implementation as well. Thanks! ...