python

More pythonic way to iterate

I am using a module that is part of a commercial software API. The good news is there is a python module - the bad news is that its pretty unpythonic. To iterate over rows, the follwoing syntax is used: cursor = gp.getcursor(table) row = cursor.next() while row: #do something with row row = cursor.next() What is the most ...

Django: saving pickled object

Hi, i have a large dictionary I'd like to save. I have pickled it using cPickle.dumps and saved the result into a TextField. When trying to retrieve it (cPicle.loads) i get the following error: loads() argument 1 must be string, not unicode Does anybody have any experience in serializing python objects and storing them in a DB using D...

Change|Assign parent for the Model instance on Google App Engine Datastore

Is it possible to change or assign new parent to the Model instance that already in datastore? For example I need something like this task = db.get(db.Key(task_key)) project = db.get(db.Key(project_key)) task.parent = project task.put() but it doesn't works this way because task.parent is built-in method. I was thinking about creating...

python and overflowing byte?

Hi all, I need to make a variable with similar behaviour like in C lanquage. I need byte or unsigned char with range 0-255. This variable should overflow, that means... myVar = 255 myVar += 1 print myVar #!!myVar = 0!! ...

Escape whitespace in paths using nautilus script

I didn't think this would be as tricky as it turned out to be, but here I am. I'm trying to write a Nautilus script in Python to upload one or more images to Imgur just by selecting and right clicking them. It works well enough with both single images and multiple images - as long as they don't contain any whitespace. In fact, you can up...

Efficient way to access a mapping of identifiers in Python

I am writing an app to do a file conversion and part of that is replacing old account numbers with a new account numbers. Right now I have a CSV file mapping the old and new account numbers with around 30K records. I read this in and store it as dict and when writing the new file grab the new account from the dict by key. My question i...

draw circle PIL - python

Hi I am looking for a command that will draw a circle on an existing image. im=Image.open(path) looking for a function that will draw a coloured circle with radious r and center(x,y) thanks for any help provided Ariel ...

Python dictionary key missing

I thought I'd put together a quick script to consolidate the CSS rules I have distributed across multiple CSS files, then I can minify it. I'm new to Python but figured this would be a good exercise to try a new language. My main loop isn't parsing the CSS as I thought it would. I populate a list with selectors parsed from the CSS file...

Python ctypes: loading DLL from from a relative path

I have a Python module, wrapper.py, that wraps a C DLL. The DLL lies in the same folder as the module. Therefore, I use the following code to load it: myDll = ctypes.CDLL("MyCDLL.dll") This works if I execute wrapper.py from its own folder. If, however, I run it from elsewhere, it fails. That's because ctypes computes the path relativ...

is there a way to make squid transparent proxy in windows ? (python)

i know there's a way using "SoftPerfect Bandwidth Manager" but what i want is to use python to do that, maybe using pypcap or something like that thanks ...

Writing a program to scrape forums

Hi, I need to write a program to scrape forums. Should I write the program in Python using the Scrapy framework or should I use Php cURL? Also is there a Php equivalent to Scrapy? Thanks ...

Pyserial : How to send data to drive SIPO

Dear All .. I'm learning to drive a stepper motor with Python. It's hard now to find a PC with paralel port. So My plan is using a USB-Serial .. and a SIPO (serial in parallel out) shift register circuit. As you know with this circuit we need to send a binary data in series and this data will be stored in it's register. Next we need to...

convert string to float without silent NaN/Inf conversion

I'd like convert strings to floats using Python 2.6 and later, but without silently converting things like 'NaN' and 'Inf' to float objects. I do want them to be silently ignored, as with any text that isn't valid as a float representation. Before 2.6, float("NaN") would raise a ValueError on Windows. Now it returns a float for which ...

Rails and Python hosting problem

I am trying to host some files/rails app in the port 8080 for external access. For python I am using the SimpleHTTPServer module, and for rails, webrick. However, both of them does not work very well. I don't get the response back, and, sometimes, if I get it, it's VERY slow. Nevertheless, apache works very well on the port 8080 (i am no...

In google app engine, how to iterate through form fields (python, wsgiref.handlers)

Using python and wsgiref.handlers, I can get a single variable from a form with self.handler.request.get(var_name), but how do I iterate through all form variables, be they from GET and POST? Is it something like this? for field in self.handler.request.fields: value = self.handler.request.get(field) Again, it should include both fi...

in pylongs, is there a way to loop through all the controllers and actions?

in pylons, is it possible to loop through all the controllers and their actions? I want to create a javascript object that has all the controllers and their actions ...

Python - excel - xlwt: colouring every second row

Hi, i just finish some MYSQL to excel script with xlwt and I need to colour every second row for easy reading. I have tried this: row = easyxf('pattern: pattern solid, fore_colour blue') for i in range(0,10,2): ws0.row(i).set_style(row) Alone this colouring is fine, but when when I write my data rows are again white. Can some ple...

Definitive way to parse alphanumeric CSVs in Python with scipy/numpy

I've been trying to find a good and flexible way to parse CSV files in Python but none of the standard options seem to fit the bill. I am tempted to write my own but I think that some combination of what exists in numpy/scipy and the csv module can do what I need, and so I don't want to reinvent the wheel. I'd like the standard feature...

How to create a HTML world map with GeoDjango ?

The GeoDjango tutorial explains how to insert world borders into a spatial database. I would like to create a world Map in HTML with these data, with both map and area tags. Something like that. I just don't know how to retrieve the coordinates for each country (required for the area's coords attribute). from world.models import World...

Google App Engine: TypeError problem with Models

I'm running Google App Engine on the dev server. Here is my models file: from google.appengine.ext import db import pickle import re re_dept_code = re.compile(r'[A-Z]{2,}') re_course_number = re.compile(r'[0-9]{4}') class DependencyArcHead(db.Model): sink = db.ReferenceProperty() tails = db.ListProperty() class DependencyA...