python

What encoding do normal python strings use?

i know that django uses unicode strings all over the framework instead of normal python strings. what encoding are normal python strings use ? and why don't they use unicode? ...

Need performance on postGIS with GeoDjango

This is the first time I'm using GeoDjango with postGIS. After installation and some tests with everything running fine I am concerned about query performance when table rows will grow. I'm saving in a geometry point longitudes and latitudes that I get from Google geocoding (WGS84, or SRID 4326). My problem is that distance operations a...

restrict movable area of qgraphicsitem

Is there a way to restrict the area where a QGraphicsItem like QRect can be moved when setFlag(ItemIsMovable) is set? I'm new to pyqt and trying to find a way to move an item with the mouse, and the restrict it to only vertically/horizontally. Thanks! ...

Python: Changing process name with setproctitle

Hi I have a python script which launches a number of C++ programs, each program is passed a command line parameter as shown below process_path "~/test/" process_name "test" num_process = 10 for p in range(1, num_processes, 1): subprocess.Popen([process_path + process_name, str(p)], shell = False) Is it possible to us setproctit...

Python book/ tutorial to read after finishing with the official tutorial

I just finished reading the official Python tutorial and learnt a lot. I have written a few programs for my own use and feel confident enough about the language to some extent. However, the tutorials are not complete. I have seen people make mention of stuff like __getattr__ and decorators - stuff which I have no idea about since the tu...

add nods and attribute list and KeyError!

Hi! I have nodes with a list of attributes for each called 'times' in my case. I made a simple model like this and I get KeyError'times'. I need my graph save each node with a list of 'times' as an attribute. How can I fix it? import networkx as nx G = nx.DiGraph() for u in range(10): for t in range(5): if G.has_node(u): ...

Project Euler problem 67 not quite correct...

I have the following Python code, which I wrote for the sister problem 18. It works perfectly for problem 18, but is slightly out for problem 67. I can't for the life of me figure out why. triangle = [ [59], [73, 41], [52, 40, 9], [26, 53, 6, 34], [10, 51, 87, 86, 81], [61, 95, 66, 57, 25, 68], ... ] def max_adjacent(row,col): ret...

Download, extract and read a gzip file in Python

I'd like to download, extract and iterate over a text file in Python without having to create temporary files. basically, this pipe, but in python curl ftp://ftp.theseed.org/genomes/SEED/SEED.fasta.gz | gunzip | processing step Here's my code: def main(): import urllib import gzip # Download SEED database print 'Dow...

Python + JSON, what happened to None?

Dumping and loading a dict with None as key, results in a dict with "null" as the key. Values are un-affected, but things get even worse if a string-key "null" actually exists. What am I doing wrong here? Why cant i serialize/deserialize a dict with "None" keys? Example >>> json.loads(json.dumps({'123':None, None:'What happened to No...

How to replace (or strip) an extension from a filename in Python ?

Hi, Is there a built-in function in Python that would replace (or remove, whatever) the extension of a filename (if it has one) ? Example: print replace_extension('/home/user/somefile.txt', '.jpg') In my example: /home/user/somefile.txt would become /home/user/somefile.jpg Sorry if my question is really trivial, but I'm learning Py...

Unbound error using python's unittest module

Hello, everyone. I would like a seperate class to run all of my tests, and then call that class from main to display the results. Unfortunately, I am getting an error like this: Traceback (most recent call last): File "/home/dhatt/workspace/pyqt_DALA_ServiceTracker/src/Main.py", line 21, in <module> allsuite = unittest.TestLoade...

{solved}: PHP exec() problem with custom Python module

Hi, * edit * After reinstalling the module, everything worked fine. I have installed a python module on my webserver. When I do "whereis python" I get following path: python: /usr/bin/python2.4 /usr/bin/python /usr/lib/python2.4 /usr/include/python2.4 /usr/share/man/man1/python.1.gz Later when I check my modules path, it was install...

Wxwidgets and Pyqt

Hello, is there a similar function PyOnDemandOutputWindow in Pyqt? This function redirect the console output to a separate window. Sorry for my english. ...

Is there an analog of Python's vars() method in Ruby?

In Python there is vars() method which returns a dictionary of names of local variables as keys, and their values, so it is possible to do something like this: a = 1 b = 2 "%(a)s %(b)s" % vars() Is there an analog of vars() in Ruby? The closest construct I can think of is local_variables.inject({}) {|res,var| res[var] = eval(var.to_...

Regex to find all sentences of text ?

Hello everyone, I have been trying to teach myself Regexes in python and I decided to print out all the sentences of a text. I have been tinkering with the regular expressions for the past 3 hours to no avail. I just tried the following but couldn't do anything. p = open('anan.txt') process = p.read() regexMatch = re.findall('^[A-Z].+...

Confusing python problem

As part of a large python program I have the following code: for arg in sys.argv: if "name=" in arg: name = arg[5:] print(name) elif "uname=" in arg: uname = arg[6:] print(uname) elif "password=" in arg: password = arg[9:] print(password) elif "bday=...

Installing lxml when Codespeak.net is down.

Codespeak.net is down and something, somewhere in my buildout wants to easy_install lxml from it, despite me boopstrapping with pip, having it installed already and removing it from my buildout files. How else can I get round this? ...

Descriptors in global scope?

The descriptor protocol in Python 2.6 is only defined for class definitions, and thus can only be used by instances. Is there some equivalent for instrumenting get/set of globals? I'm trying to speed up the importing of a module which interacts with the host system, and as such has to perform some expensive probing of the host. The res...

What is the best escape character strategy for Python/MySQL combo?

This is my query. cursor2.execute("update myTable set `"+ str(row[1]) +"` = \"'" + str(row[3]) +"'\" where ID = '"+str(row[0])+"'") It is failing when row values have double quotes "some value". How do I escape all special characters? Any feedback is highly appreciated. Thank you... ...

python threading: memory model and visibility

Does python threading expose issues of memory visibility and statement reordering as Java does? Since I can't find any reference to a "Python Memory Model" or anything like that, despite the fact that lots of people are writing multithreaded Python code, I'm guessing that these gotchas don't exist here. No volatile keyword, for instance....