python

Python loop | "do-while" over a tree

Is there a more Pythonic way to put this loop together?: while True: children = tree.getChildren() if not children: break tree = children[0] UPDATE: I think this syntax is probably what I'm going to go with: while tree.getChildren(): tree = tree.getChildren()[0] ...

virtualenv, mysql-python, pip: anyone know how?

I'm trying to install the mysql bindings in a virtualenv. I'd prefer to use pip or easy_install. pip gives me the following error: File "setup_posix.py", line 24, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found easy_install either gets a 404 from sourcefo...

Python distutils - copy_tree with filter

I want to copy a data directory into my distribution dir. copy_tree does this just fine. However, the project is also an svn repository, and I don't want the distribution to have all the .svn files that the data dir has. Is there any easy way to do a copy_tree excluding the .svn files, or should I just write my own recursive dir copy? I ...

Parse a cron entry in Python

All. I am trying to find a python module that I can use to parse a cron entry and get the next time it will run. With perl I use the Schedule::Cron::Events module but I would like to convert to python. Thanks in advance. ...

py2exe'd version of GTK app can't read png files

I'm working on making a py2exe version of my app. Py2exe fails at copying some modules in. My original app loads .png files fine, but the exe version does not: Traceback (most recent call last): File "app.py", line 1, in <module> from gui.main import run File "gui\main.pyc", line 14, in <module> File "gui\controllers.pyc", li...

Please help me with this program to parse a file into an XML file.

To parse an input text file and generate a) an XML file and b) an SVG (also XML) file. The input text file (input.txt) contains the description of a number of produce distribution centers and storage centers around the country. Each line describes either a single distribution center (dcenter) or a storage center, each with a number of p...

model/view relationships

i have a model ready with the various form fields. how do i make those form fields get saved into the database? i tried reading the form documentation but it is so confusing. i know if i get it working, i will understand. can anyone help define a views.py function? ...

urlopen error 10045, 'address already in use' while downloading in Python 2.5 on Windows

I'm writing code that will run on Linux, OS X, and Windows. It downloads a list of approximately 55,000 files from the server, then steps through the list of files, checking if the files are present locally. (With SHA hash verification and a few other goodies.) If the files aren't present locally or the hash doesn't match, it downloads t...

Django: Get an object form the DB, or 'None' if nothing matches

Is there any Django function which will let me get an object form the database, or None if nothing matches? Right now I'm using something like: foo = Foo.objects.filter(bar=baz) foo = len(foo) > 0 and foo.get() or None But that's not very clear, and it's messy to have everywhere. ...

Generic Foreign Keys and get_or_create in django 1.0: Broken?

As you can see, create() works, but get_or_create() doesn't. Am I missing something obvious here? In [7]: f = FeedItem.objects.create(source=u, dest=q, type="greata") In [8]: f, created = FeedItem.objects.get_or_create(source=u, dest=q, type="greata") --------------------------------------------------------------------------- FieldErro...

What is a good reference for Server side development?

I am more interested in the design of the code (i.e functional design vs object oriented design). What are the best practices and what is the communities thoughts on this subject? Not that it should matter, but I am working with Apache and Python technology stack. ...

Python optparse defaults vs function defaults

I'm writing a python script which I would like to be able to both call from the command line and import as a library function. Ideally the command line options and the function should use the same set of default values. What is the best way to allow me to reuse a single set of defaults in both places? Here's the current code with duplic...

Converting urls into lowercase?

Is there any straightforward to convert all incoming urls to lowercase before they get matched against urlpatterns in run_wsgi_app(webapp.WSGIApplication(urlpatterns))? ...

Python: how to write a data struct to a file as text (not pickled)

Is there a way to write python data structs to a file as text. e.g. an app is running and has a variable/object: OPTIONS = ('ON', 'OFF', ) I need to write/merge the OPTIONS tuple into another file, not as a pickled object, but as text, verbatim: OPTIONS = ('ON', 'OFF', ) I could traverse the tuple, and one by one write the elements i...

How do you retrieve the tags of a file in a list with Python (Windows Vista)?

I want to make something of a tag cloud for various folders I have, but unfortunately, I can't seem to find a way to access the tags of a file in Windows Vista. I tried looking at the win32 module, and os.stat, but I can't seem to find a way. Can I get some help on this? ...

Determining if stdout for a Python process is redirected

I've noticed that curl can tell whether or not I'm redirecting its output (in which case it puts up a progress bar). Is there a reasonable way to do this in a Python script? So: $ python my_script.py Not redirected $ python my_script.py > output.txt Redirected! ...

can't install lxml (python 2.6.3, osx 10.6 snow leopard)

I try to: easy_install lxml and I get this error: File "build/bdist.macosx-10.3-fat/egg/setuptools/command/build_ext.py", line 85, in get_ext_filename KeyError: 'etree' any hints? ...

How to access file metadata with Python?

Hi, I'm trying to write a program in python that retrieves and updates file metadata on windows. I've tried searching on Google regarding what modules to use but I haven't found anything very concrete or useful. Some people suggested the stat module which can give you info such as file access and last modification. But I'm looking to r...

Python Pypi: what is your process for releasing packages for different Python versions? (Linux)

I've got several eggs I maintain on Pypi but up until now I've always focused on Python 2.5x. I'd like to release my eggs under both Python 2.5 & Python 2.6 in an automated fashion i.e. running tests generating doc preparing eggs uploading to Pypi How do you guys achieve this? A related question: how do I tag an egg to be "version ...

Simple Facebook Connect in Google App Engine (Python)

Does anyone have a simple and successful demo implementation of facebook connect in an google app engine application. I am developing an web application and want facebook connect to be the primary method for logging in. ...