python

Django official tutorial for the absolute beginner, absolutely failed!

Not that level of failure indeed. I just completed the 4 part tutorial from djangoproject.com, my administration app works fine and my entry point url (/polls/) works well, with the exception that I get this http response: No polls are available. Even if the database has one registry. Entering with the admin app, the entry shows up th...

Consuming Python COM Server from .NET

Hi all, I wanted to implement python com server using win32com extensions. Then consume the server from within the .NET. I used the following example to implement the com server and it runs without a problem but when I try to consume it using C# I got FileNotFoundException with the following message "Retrieving the COM class factory for...

Recursive delete in google app engine

I'm using google app engine with django 1.0.2 (and the django-helper) and wonder how people go about doing recursive delete. Suppose you have a model that's something like this: class Top(BaseModel): pass class Bottom(BaseModel): daddy = db.ReferenceProperty(Top) Now, when I delete an object of type 'Top', I want all the ass...

How do you get Python documentation in Texinfo Info format?

Since Python 2.6, it seems the documentation is in the new reStructuredText format, and it doesn't seem very easy to build a Texinfo Info file out of the box anymore. I'm an Emacs addict and prefer my documentation installed in Info. Does anyone have Python 2.6 or later docs in Texinfo format? How did you convert them? Or, is there a m...

Unable to make a MySQL database of SO questions by Python

Brent's answer suggests me that has made a database of SO questions such that he can fast analyze the questions. I am interested in making a similar database by MySQL such that I can practice MySQL with similar queries as Brent. The database should include at the least the following fields (I am guessing here, since the API of SO's api...

fast and easy way to template xml files in python

Right now I've hard coded the whole xml file in my python script and just doing out.write(), but now it's getting harder to manage because i have multiple types of xml file. What is the easiest and quickest way to setup templating so that I can just give the variable names amd filename? ...

How to modify a NumPy.recarray using its two views.

Hi all. I am new to Python and Numpy, and I am facing a problem, that I can not modify a numpy.recarray, when applying to masked views. I read recarray from a file, then create two masked views, then try to modify the values in for loop. Here is an example code. import numpy as np import matplotlib.mlab as mlab dat = mlab.csv2rec(args...

Unicode friendly alphabetic pattern for python regex?

I'm looking for a pattern equivalent to \w, and which doesn't match numeric pattern. I cannot use [a-zA-Z] because I would like it to match japanese kanjis as well. Is there a way to write something like [\w^[0-9]] ? Is there an equivalent of [:alpha:] in python regex? ...

how to tell a variable is iterable but not a string

I have a function that take an argument which can be either a single item or a double item: def iterable(arg) if #arg is an iterable: print "yes" else: print "no" so that: >>> iterable( ("f","f") ) yes >>> iterable( ["f","f"] ) yes >>> iterable("ff") no The problem is that string is technically iterable, ...

Python: linking/binding variables together in a dictionary

Hi all - first post, so play nice! I have a fairly basic question about Python dictionaries. I would like to have some dict value that updates when another variable is changed (or at least recalculated when it is next called) - eg: mass = 1.0 volume = 0.5 mydict = {'mass':mass,'volume':volume} mydict['density'] = mydict['mass']/mydict[...

How do I find out what Python libraries are installed on my Mac?

I'm just starting out with Python, and have found out that I can import various libraries. How do I find out what libraries exist on my Mac that I can import? How do I find out what functions they include? I seem to remember using some web server type thing to browse through local help files, but I may have imagined that! ...

item frequency in a python list of dictionaries

Ok, so I have a list of dicts: [{'name': 'johnny', 'surname': 'smith', 'age': 53}, {'name': 'johnny', 'surname': 'ryan', 'age': 13}, {'name': 'jakob', 'surname': 'smith', 'age': 27}, {'name': 'aaron', 'surname': 'specter', 'age': 22}, {'name': 'max', 'surname': 'headroom', 'age': 108}, ] and I want the 'frequency' of the items wit...

JSON serialization in Spidermonkey

I'm using python-spidermonkey to run JavaScript code. In order to pass objects (instead of just strings) to Python, I'm thinking of returning a JSON string. This seems like a common issue, so I wonder whether there are any facilities for this built into either Spidermonkey or python-spidermonkey. (I do know about uneval but that is not...

file I/O in Spidermonkey

Thanks to python-spidermonkey, using JavaScript code from Python is really easy. However, instead of using Python to read JS code from a file and passing the string to Spidermonkey, is there a way to read the file from within Spidermonkey (or pass the filepath as an argument, as in Rhino)? ...

Server Logging - in Database or Logfile?

I've been working on a server and I'm starting to implement logging. However, I'm not sure whether I should use the db for logging, or just a plaintext file. I'm planning on logging some basic information for every request (what type of request, ip address of request, session tracking). For some requests there will be extended informa...

Can two versions of the same library coexist in the same Python install?

The C libraries have a nice form of late binding, where the exact version of the library that was used during linking is recorded, and thus an executable can find the correct file, even when several versions of the same library are installed. Can the same be done in Python? To be more specific, I work on a Python project that uses some...

How do you call Python code from C code?

I want to extend a large C project with some new functionality, but I really want to write it in Python. Basically, I want to call Python code from C code. However, Python->C wrappers like SWIG allow for the OPPOSITE, that is writing C modules and calling C from Python. I'm considering an approach involving IPC or RPC (I don't mind ha...

Random Python dictionary key, weighted by values

hello, I have a dictionary where each key had a list of variable length, eg: d = { 'a': [1, 3, 2], 'b': [6], 'c': [0, 0] } Is there a clean way to get a random dictionary key, weighted by the length of its value? random.choice(d.keys()) will weight the keys equally, but in the case above I want 'a' to be returned roughly half the ...

Ruby on Rails vs. Django

Possible Duplicate: Rails or Django? (or something else?) These are two web frameworks that are becoming (or have been in many circles) popular. I was wondering what are the advantages and disadvantages of each? Feel free to comment on Ruby and Python pros and cons also. Two disadvantages I am speculative about for RoR is the s...

PyQt4 mac drawer positioning

I am using PyQt4 for an application I only plan on using on macs. So I wanted to make it look more like a mac application. To do so I am trying to incorporate sheets and drawers instead of spawning other windows. I have got a drawer to come up but it comes up on the left side of the application. Is there any way to make the drawer ...