Dynamically creating Django models with `type`

I have 20+ MySQL tables, prm_a, prm_b, … with the same basic structure but different names, and I’d like to associate them with Django model classes without writing each one by hand. So, feeling …

How to get PID by process name?

Is there any way I can get the PID by process name in Python? PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND …

query from postgresql using python as dictionary

I’m using Python 2.7 and postgresql 9.1. Trying to get dictionary from query, I’ve tried the code as described here: http://wiki.postgresql.org/wiki/Using_psycopg2_with_PostgreSQL import psycopg2 …

Pip freeze vs. pip list

A comparison of outputs reveals differences: Pip’s documentation states but what is “requirements format,” and why does pip list generate a more comprehensive list than pip freeze? Answer When you are using a virtualenv, you can specify a requirements.txt file to install all the dependencies. A typical usage: The packages need to be in a specific format for pip to understand, which is That is the “requirements format”. Here, django==1.4.2 implies install django version 1.4.2 (even though the latest is 1.6.x). If you do not specify ==1.4.2, the latest version available would be installed. You can read more in “Virtualenv

Setting Cell Formats with xlwt format strings

I’ve looked around for several different xlwt formats for cells, but I can’t find a comprehensive list. Excel provides the following options for cell content formatting: (general, number, currency, …

What do ellipsis […] mean in a list?

I was playing around in python. I used the following code in IDLE: The output was: What is this […]? Interestingly I could now use this as a list of list of list up to infinity i.e. I could write the above as long as I wanted and it would still work. EDIT: How is it represented in memory? What’s its use? Examples of some cases where it is useful would be helpful. Any link to official documentation would be really useful. Answer It means that you created an infinite list nested inside itself, which can not be printed. p

How to check if a specific integer is in a list

I want to know how to make an if statement that executes a clause if a certain integer is in a list. All the other answers I’ve seen ask for a specific condition like prime numbers, duplicates, etc. …

How to print a string at a fixed width?

I have this code (printing the occurrence of the all permutations in a string) def splitter(str): for i in range(1, len(str)): start = str[0:i] end = str[i:] yield (start,…

selecting attribute values from lxml

I want to use an xpath expression to get the value of an attribute. I expected the following to work but this gives an error : Am I wrong to expect this to work? Answer find and findall only implement a subset of XPath. Their presence is meant to provide compatibility with other ElementTree implementations (like ElementTree and cElementTree). The xpath method, in contrast, provides full access to XPath 1.0: However, you could instead use get: or attrib: