python

permissive equality test on string

Hi, I'm a python newbie with a problem too hard to tackle. I have a string defining a path, were all the spaces have been converted to underscores. How can I find if it corresponds to a real path? e.g. a string like /some/path_to/directory_1/and_to/directory_2 with a real path: /some/path_to/directory 1/and_to/directory 2 notice that ...

Themes for python e-commerce solutions.

Hi all. There are two good open source python e-commerce solutions exist: Satchmo and LFS. But I can't find any theme for them. Does at least one open source theme for them exist? There are thousands themes for Magento, osCommerce, OpenCart, but zero themes for Satchmo. Thanks. ...

What is correct python syntax for this kind of list comprehension?

task: {x*y such that x belongs to S & y is iteration count } where S is some other set something like this: j=0 [i*j for j++ and i in S] [s1*1, s2*2, s3*3...] ...

How can I pairwise sum two equal-length tuples

How can I get the pairwise sum of two equal length tuples? For example if I have (0,-1,7) and (3,4,-7) I would like to have (3,3,0) as answer. ...

uploading records of list of files in parallel using pyton to DB

I have a list of files each file have mass of records separting by \n , i need to proccess those records in parallel and upload them to some sql server could someone provide an idea what is the best way to do this with python ...

Whats the correct way of writing this list comprehension?

I'm getting an error: name 'i' is not defined k = [ [ rids[i][j][0]['a'] * rids[i][j][1]['b'] for i in range(0,10) ] for j in range(0,len(furs[i])) ] but k = [ rids[i][j][0]['a'] * rids[i][j][1]['b'] for i in range(0,10) for j in range(0,len(furs[i])) ] works suprisingly! EDIT: What is the correct way of writi...

wx.TreeCtrl drag and drop, copy and move

I'm trying to implement drag and drop on a wx.TreeCtrl and I need to handle both "copy" and "move" operations (if the user keeps CTRL pressed). First of all, I searched the wiki for an example and I'm confused as to which method to use.. Should I use DropSource/DropTarget or just handle EVT_TREE_BEGIN_DRAG and EVT_TREE_END_DRAG? If the l...

Create variables from strings in Python

Is something like the following possible in Python: >>> vars = {'a': 5} >>> makevars(vars) >>> print a 5 So, makevars converts the dictionary into variables. (What is this called in general?) ...

Convert partial function to method in python

Consider the following (broken) code: import functools class Foo(object): def __init__(self): def f(a,self,b): prin...

how to highlight part of textarea html code

I want to achieve a python version web regexbuddy,and i encounter a problem,how to highlight match values in different color(switch between yellow and blue) in a textarea,there has a demo what exactly i want on http://regexpal.com,but i was a newbie on js,i didn't understand his code meaning. any advice is appreciated ...

Optimizing mean in python

I have a function which updates the centroid (mean) in a K-means algoritm. I ran a profiler and noticed that this function uses a lot of computing time. It looks like: def updateCentroid(self, label): X=[]; Y=[] for point in self.clusters[label].points: X.append(point.x) Y.append(point.y) self.clusters[label...

Using regex in python

Hello, i have the following problem. I want to escape all special characters in a python string. str='eFEx-x?k=;-' re.sub("([^a-zA-Z0-9])",r'\\1', str) 'eFEx\\1x\\1k\\1\\1\\1' str='eFEx-x?k=;-' re.sub("([^a-zA-Z0-9])",r'\1', str) 'eFEx-x?k=;-' re.sub("([^a-zA-Z0-9])",r'\\\1', str) I can't seem to win here. '\1' indicates the spe...

How do I create a Django model field that evaluates based on other fields?

I'll try to describe my problem with a simple example. Say I have items of type Item and every item relates to a certain type of Category. Now I can take any two items and combine into an itemcombo of type ItemCombo. This itemcombo relates to a certain category called ComboCategory. The ComboCategory is based on which categories the item...

Encoding problem downloading HTML using mechanize and Python 2.6

browser = mechanize.Browser() page = browser.open(url) html = page.get_data() print html It shows some strange characters. I suppose that it is UTF-8 string but Python doesn't know that and cannot show it properly. How can I convert this string to unicode string like u = u'test' ...

Inserting additional items into an inherited list in Django/Python

I'm using some subclasses in my Django app, and I'm continuing that logic through to my admin implementation. Currently, I have this admin defintion: class StellarObjectAdmin(admin.ModelAdmin): list_display = ('title','created_at','created_by','updated_at','updated_by) Now, I have a Planet class, that is a subclass of StellarObject...

python, subprocess: reading output from subprocess

I have following script: #!/usr/bin/python while True: x = raw_input() print x[::-1] I am calling it from ipython: In [5]: p = Popen('./script.py', stdin=PIPE) In [6]: p.stdin.write('abc\n') cba and it works fine. However, when I do this: In [7]: p = Popen('./script.py', stdin=PIPE, stdout=PIPE) In [8]: p.stdin.write('...

Matplotlib draw boxes

Hi, I have a set of data, where each value has a (x, y) coordinate. Different values can have the same coordinate. And I want to draw them in a rectangular collection of boxes. For example, if I have the data: A -> (0, 0) B -> (0, 1) C -> (1, 2) D -> (0, 1) I want to get the following drawing: 0 1 2 +++++++++++++ 0 + A + ...

PyObject_CallFunction Access violation writing location 0x0000000c.

I am trying to wrap a c communication library in python and am having some trouble when I attempt to handle large amounts of data. The following code will work for smaller messages but when the message is larger than 400MB I get the following error from the PyObject_CallFunction call: Unhandled exception at 0x1e00d65f in python.exe: 0xC...

Does File exist in Python?

Possible Duplicate: Pythonic way to check if a file exists? How can Check if file exist with python 2.6? If file exists run exec redo.py. If file does not exists exec file start.py The file is a 0kb, but name Xxx100926.csv Ans seems to be from os path import exists from __future__ import with_statement if exists('...

C# vs Python: XML Handling/Processing Productivity

Hello, I am planning on writing a medium size web application that will be XML heavy. I will need to do heavy xml processing. When a user requests a webpage the program will fetch the XML from the database then it will process the XML then render the results to the browser. The XML is not big but i will need to make changes to the xml ru...