python

Psycopg2 doesn't like table names that start with a lower case letter

I am running ActiveState's ActivePython 2.6.5.12 and PostgreSQL 9.0 Beta 1 under Windows XP. If I create a table with an upper case first letter (i.e. Books), psycopg2 returns the "Programming Error: relation "books" does not exist" error message when I run the select statement: execute("SELECT * FROM Books"). The same error is returned...

python: strip comma end of string

how do i strip comma from the end of an string, i tried awk = subprocess.Popen([r"awk", "{print $10}"], stdin=subprocess.PIPE) awk_stdin = awk.communicate(uptime_stdout)[0] print awk_stdin temp = awk_stdin t = temp.strip(",") also tried t = temp.rstrip(","), both don't work. ...

Child processes created with python multiprocessing module won't print

I have a problem with the code below, and with any code that uses the print function in the child processes: I can't see any printed statements, even if I use sys.std[err|out].write('worker') in place of print. This is the code (from the official python documentation): from multiprocessing import Process def f(name): print 'hello'...

Can distribute setuptools be used to port packages implemented in python 2 to 3

Found some info on porting packages from python 2 to 3 using distribute setuptools in below link. http://packages.python.org/distribute/python3.html I have a C api which could be build using python 2.x, but i need to build it in python 3.x. Can it be done using distribute. Do anyone have idea on this? ...

Can I use django.contrib.gis on GAE?

Can I use GeoDjango with GAE / BigTable? ...

SwA (Soap with attachments) in python?

Does anybody knows if there is out there any library with support for SwA in Python (MIME multipart messages). I've tried with ZSI without success. ...

merging indexed array in Python

Suppose that I have two numpy arrays of the form x = [[1,2] [2,4] [3,6] [4,NaN] [5,10]] y = [[0,-5] [1,0] [2,5] [5,20] [6,25]] is there an efficient way to merge them such that I have xmy = [[0, NaN, -5 ] [1, 2, 0 ] [2, 4, 5 ] [3, 6, NaN] [4, NaN, NaN] ...

Good looking programs that are built using wxPython for their UI

I need inspiration and motivation so I'm trying to find examples of different programs that have interesting and attractive UI's created free using wxPython. My searches have been slow to find results. I'm hoping you guys know of some of the best ones out there. btw, I've seen these: http://www.wxpython.org/screenshots.php and the l...

Using MySQL in Pydev Eclipse

Hi, I am trying to access a MySQL database with python through Pydev Eclipse. I have installed the necessary files to access MysQL from python and I can access the database only when I write code in Python IDLE environment and run it from command prompt. However I am not able to run my applications from Pydev. when I use this "import M...

Is it possible to add IPTC data to a JPG using python when no such data already exists?

With the IPTCInfo module under Python (http://snippets.dzone.com/posts/show/768 for more info) it's possible to read, modify and write IPTC info to pictures. However, if a JPG doesn't already have IPTC information, the module simply raises an exception. It doesn't seem to be able to create and add this metadata information itself. Wh...

A question about DOM parser used with Python

I'm using the following python code to search for a node in an XML file and changing the value of an attribute of one of it's children.Changes are happening correctly when the node is displayed using toxml().But, when it is written to a file, the attributes rearrange themselves(as seen in the Source and the Final XML below). Could anyone...

Help with Python structure in *nixes.

I came from a Windows background whern it comes to development environments. I'm used to run .exe's from everything I need to run and just forget. I usually code in php, javascript, css, html and python. Now, I have to use Linux at my work, in a non changeable Ubuntu 8.04, with permissions to upgrade my system using company's repositor...

Implementing "select distinct ... from ..." over a list of Python dictionaries

Hi folks, Here is my problem: I have a list of Python dictionaries of identical form, that are meant to represent the rows of a table in a database, something like this: [ {'ID': 1, 'NAME': 'Joe', 'CLASS': '8th', ... }, {'ID': 1, 'NAME': 'Joe', 'CLASS': '11th', ... }, ...] I have already written a function to ge...

How do you store accented characters coming from a web service into a database?

I have the following word that I fetch via a web service: André From Python, the value looks like: "Andr\u00c3\u00a9". The input is then decoded using json.loads: >>> import json >>> json.loads('{"name":"Andr\\u00c3\\u00a9"}') >>> {u'name': u'Andr\xc3\xa9'} When I store the above in a utf8 MySQL database, the data is stored like the...

Python datetime to Unix timestamp

I have to create an "Expires" value 5 minutes in the future, but I have to supply it in UNIX Timestamp format. I have this so far, but it seems like a hack. def expires(): '''return a UNIX style timestamp representing 5 minutes from now''' epoch = datetime.datetime(1970, 1, 1) seconds_in_a_day = 60 * 60 * 24 five_minute...

if else-if making code look ugly any cleaner solution?

I have around 20 functions (is_func1, is_fucn2, is_func3...) returning boolean I assume there is only one function which returns true and I want that! I am doing: if is_func1(param1, param2): # I pass 1 to following abc(1) # I pass 1 some_list.append(1) elif is_func2(param1, param2): # I pass 2 to following abc(2) ...

Recurrent yearly date alert in Python

A user can set a day alert for a birthday. (We do not care about the year of birth) He also picks if he wants to be alerted 0, 1, 2, ou 7 days (Delta) before the D day. Users have a timezone setting. I want the server to send the alerts at 8 am on the the D day - deleta +- user timezone Example: 12 jun, with "alert me 3 days before" w...

Cascading Dropdown List

I am working on a web app and trying to code a form with two dropdown lists. The list in the second dropdown will be dependent on the selection from the first one. The task itself isn’t too complicated except that once the first selection is made, I need to make a database call to pull the data for the second dropdown. This is where I...

[python] traversing an object tree

Hi there, I'm trying to find information on different ways to traverse an object tree in python. I don't know much about the language in general yet, so any suggestions/techniques would be welcome. Thanks so much jml ...

Help with cURL in Python

Hi, I have to POST a request to a server. In the API documentation of the website there is this example that uses cURL in PHP: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://api.website.com'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "request=$wrapper"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, ...