python

Python - MYSQL - Select leading zeros

Hi When using Python and doing a Select statement to MYSQL to select 09 from a column the zero gets dropped and only the 9 gets printed. Is there any way to pull all of the number i.e. including the leading zero? ...

Calling Python from Objective-C

I'm developing a Python/ObjC application and I need to call some methods in my Python classes from ObjC. I've tried several stuffs with no success. How can I call a Python method from Objective-C? My Python classes are being instantiated in Interface Builder. How can I call a method from that instance? ...

In Django how to show a list of objects by year

I have theses models: class Year(models.Model): name = models.CharField(max_length=15) date = models.DateField() class Period(models.Model): name = models.CharField(max_length=15) date = models.DateField() class Notice(models.Model): year = models.ForeignKey(Year) period = models.ForeignKey(Period, blank=True, ...

Do any Python ORMs (SQLAlchemy?) work with Google App Engine?

I'd like to use the Python version of App Engine but rather than write my code specifically for the Google Data Store, I'd like to create my models with a generic Python ORM that could be attached to Big Table, or, if I prefer, a regular database at some later time. Is there any Python ORM such as SQLAlchemy that would allow this? ...

How to catch 404 error in urllib.urlretrieve

Background: I am using urllib.urlretrieve, as opposed to any other function in the urllib* modules, because of the hook function support (see reporthook below) .. which is used to display a textual progress bar. This is Python >=2.6. >>> urllib.urlretrieve(url[, filename[, reporthook[, data]]]) However, urlretrieve is so dumb that it ...

Embedding Windows Python in Cygwin/GCC C++ program

I am currently working on a Cygwin/GCC application written in C++. The application requires embedding of python to run plug-ins, I've successfully embedded using the Cygwin python libraries and was able to run simple python files as part of the program. However, the python files now require the use of a windows GUI framework (wxPython), ...

Is it possible to peek at the data in a urllib2 response?

I need to detect character encoding in HTTP responses. To do this I look at the headers, then if it's not set in the content-type header I have to peek at the response and look for a "<meta http-equiv='content-type'>" header. I'd like to be able to write a function that looks and works something like this: response = urllib2.urlopen("...

Python assert -- improved introspection of failure?

This is a rather useless assertion error; it does not tell the values of the expression involved (assume constants used are actually variable names): $ python -c "assert 6-(3*2)" [...] AssertionError Is there a better assert implementation in Python that is more fancy? It must not introduce additional overhead over execution (except ...

How I can add a Widget or a Region to an Status Icon in PyGTK

Hello All, This is my first question in StackOverflow, so I would try to explain my self the best I can. I made an small app trying to emularte the windows Procastination Killer Application, using pygtk and pygame for the sound alerts. Here is a video of my little app running http://www.youtube.com/watch?v=FmE-QPA9p-8 My Issue is tha...

Transparency in PNGs with reportlab 2.3

I have two PNGs that I am trying to combine into a PDF using ReportLab 2.3 on Python 2.5. When I use canvas.drawImage(ImageReader) to write either PNG onto the canvas and save, the transparency comes out black. If I use PIL (1.1.6) to generate a new Image, then paste() either PNG onto the PIL Image, it composits just fine. I've double...

cURL: https through a proxy

I need to make a cURL request to a https URL, but I have to go through a proxy as well. Is there some problem with doing this? I have been having so much trouble doing this with curl and php, that I tried doing it with urllib2 in Python, only to find that urllib2 cannot POST to https when going through a proxy. I haven't been able to ...

Simulate multiple IP addresses for testing

I need to simulate multiple embedded server devices that are typically used for motor control. In real life, there can be multiple servers on the network and our desktop software acts as a client to all the motor servers simultaneously. We have a half-dozen of these motor control servers on hand for basic testing, but it's getting expe...

Running function 5 seconds after pygtk widget is shown

How to run function 5 seconds after pygtk widget is shown? ...

Fast string to integer conversion in Python

A simple problem, really: you have one billion (1e+9) unsigned 32-bit integers stored as decimal ASCII strings in a TSV (tab-separated values) file. Conversion using int() is horribly slow compared to other tools working on the same dataset. Why? And more importantly: how to make it faster? Therefore the question: what is the fastest wa...

Is the implementation of response.info().getencoding() broken in urllib2?

I would expect the output of getencoding in the following python session to be "ISO-8859-1": >>> import urllib2 >>> response = urllib2.urlopen("http://www.google.com/") >>> response.info().plist ['charset=ISO-8859-1'] >>> response.info().getencoding() '7bit' This is with python version 2.6 ('2.6 (r26:66714, Aug 17 2009, 16:01:07) \n[G...

Using list_filter with Intermediary Models

We have three models, Artist: class Artist(models.Model): family_name = models.CharField(max_length=50) given_name = models.CharField(max_length=50) Group: class Group(models.Model): name = models.CharField(max_length=50) members = models.ManyToManyField(Artist, through='Membership') and Membership: class Membershi...

How to calculate a date back from another date with a given number of work days

Hi I need to calculate date (year, month, day) which is (for example) 18 working days back from another date. It would be enough to eliminate just weekends. Example: I've got a date 2009-08-21 and a number of 18 workdays as a parameter, and correct answer should be 2009-07-27. thanks for any help ...

is there similar syntax to php's $$variable in python

is there similar syntax to php's $$variable in python? what I am actually trying is to load a model based on a value. for example, if the value is Song, I would like to import Song module. I know I can use if statements or lambada, but something similar to php's $$variable will be much convenient. what I am after is something similar t...

Does a UDP service have to respond from the connected IP address?

Pyzor uses UDP/IP as the communication protocol. We recently switched the public server to a new machine, and started getting reports of many timeouts. I discovered that I could fix the problem if I changed the IP that was queried from eth0:1 to eth0. I can reproduce this problem with a simple example: This is the server code: #! /u...

How to tame the location of third party contributions in Django

I have a django project which is laid out like this... myproject apps media templates django registration sorl typogrify I'd like to change it to this... myproject apps media templates site-deps django registration sorl typogrify When I attempt it the 'site-dependencies' all break. Is there a way to implement this structur...