python

Gnome, Python, and distutils (setuptools)?

Currently I'm using the auto-tools to build/install and package a project of mine, but I would really like to move to something that feels more "pythonic". My project consists of two scripts, one module, two glade GUI descriptions, and two .desktop files. It's currently a pure python project, though that's likely to change soon-ish. L...

Both Python 2 and 3 in Emacs

I have been using Emacs to write Python 2 code. Now I have both Python 2.6 and 3.0 installed on my system, and I need to write Python 3 code as well. Here is how the different versions are set up in /usr/bin: python -> python2.6* python2 -> python2.6* python2.6* python3 -> python3.0* python3.0* Is there any way to set this up so tha...

Dynamically adding a form to a Django formset with Ajax

I'd like to be able to automatically add new forms to a Django formset with an ajax function. I.e., the user clicks an "add" button and some javascript will add a new form (which is part of the formset) to the page. Thanks for the help in advance. :-) ...

How can I execute Python code without Komodo -ide?

I do that without the IDE: $ ipython $ edit file.py $ :x (save and close) It executes Python code, but not the one, where I use Pygame. It gives: WARNING: Failure executing file: In the IDE, my code executes. ...

Simple simulations for Physics in Python?

I would like to know similar, concrete simulations, as the simulation about watering a field here. What is your favorite library/internet page for such simulations in Python? I know little Simpy, Numpy and Pygame. I would like to get examples about them. ...

How to modularize a Python application

I've got a number of scripts that use common definitions. How do I split them in multiple files? Furthermore, the application can not be installed in any way in my scenario; it must be possible to have an arbitrary number of versions concurrently running and it must work without superuser rights. Solutions I've come up with are: Duplic...

Finding the workspace size (screen size less the taskbar) using GTK

How do you create a main window that fills the entire desktop without covering (or being covered by) the task bar and without being maximized? I can find the entire screen size with and set the main window accordingly with this: window = gtk.Window() screen = window.get_screen() window.resize(screen.get_width(), screen.get_height()) b...

Running SimpleXMLRPCServer in separate thread and shutting down

I have a class that I wish to test via SimpleXMLRPCServer in python. The way I have my unit test set up is that I create a new thread, and start SimpleXMLRPCServer in that. Then I run all the test, and finally shut down. This is my ServerThread: class ServerThread(Thread): running = True def run(self): self.server = #Cr...

Converting date between DD/MM/YYYY and YYYY-MM-DD?

Hello Using a Python script, I need to read a CVS file where dates are formated as DD/MM/YYYY, and convert them to YYYY-MM-DD before saving this into a SQLite database. This almost works, but fails because I don't provide time: from datetime import datetime lastconnection = datetime.strptime("21/12/2008", "%Y-%m-%d") #ValueError: ti...

Django: How to create a model dynamically just for testing

I have a Django app that requires a settings attribute in the form of: RELATED_MODELS = ('appname1.modelname1.attribute1', 'appname1.modelname2.attribute2', 'appname2.modelname3.attribute3', ...) Then hooks their post_save signal to update some other fixed model depending on the attributeN defined....

How to parse nagios status.dat file?

I'd like to parse status.dat file for nagios3 and output as xml with a python script. The xml part is the easy one but how do I go about parsing the file? Use multi line regex? It's possible the file will be large as many hosts and services are monitored, will loading the whole file in memory be wise? I only need to extract services tha...

Query distinct list of choices for Django form with App Engine Datastore

I've been trying to figure this out for hours across a couple of days, and can not get it to work. I've been everywhere. I'll continue trying to figure it out, but was hoping for a quicker solution. I'm using App Engine datastore + Django. Using a query in a view and custom forms, I was able to get a list to the form but then I was not ...

[Solved] django facebook connect missing libs?

hello, I'm trying to integrate some photo related functionality with my site and facebook. I checked out facebook connect and it seems like the way to go for this (since I don't want to make an app, just have users authenticate and then grab some content from facebook to integrate into our site) First of all, if you think there is a bet...

Why is IronPython faster than the Official Python Interpreter

According to this: http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&referringTitle=IronPython%20Performance IronPython (Python for .Net) is faster than regular Python (cPython) on the same machine. Why is this? I would think compiled C code would always be faster than the equivalent CLI bytecode. ...

py2exe for Python 3.0

Hey guys, I am looking for a Python3.0 version of "py2exe". I tried running 2to3 on the source for py2exe but the code remained broken. Any ideas? Thanks a lot. ...

Closures in Python

Hi, I've been trying to learn Python, and while I'm enthusiastic about using closures in Python, I've been having trouble getting some code to work properly: def memoize(fn): def get(key): return (False,) def vset(key, value): global get oldget = get def newget(ky): if key==ky: return...

How to chain views in Django?

I'm implementing James Bennett's excellent django-contact-form but have hit a snag. My contact page not only contains the form, but also additional flat page information. Without rewriting the existing view the contact form uses, I'd like to be able to wrap, or chain, the views. This way I could inject some additional information vi...

Extracting data from MS Word

I am looking for a way to extract / scrape data from Word files into a database. Our corporate procedures have Minutes of Meetings with clients documented in MS Word files, mostly due to history and inertia. I want to be able to pull the action items from these meeting minutes into a database so that we can access them from a web-inter...

Is there a widely used STOMP adapter for Twisted?

I checked out stomper and it didn't look complete. (I'm very new to Python) Is anybody out there using stomper in a production environment? If not, I guess I'll have to roll out my own Twisted Stomp adapter. Thanks in advance! ...

Symbolic Mathematics Python?

I am extreamly interested in math and programming and planning to start symbolic math project from scratch. Is this good project idea? Where to start? How should one approach this project? Any good resources? Thanks in advance. ...