python

Dealing with special floating point values in Python

I am writing a simple app that takes a bunch of numerical inputs and calculates a set of results. (The app is in PyGTK but I don't think that's relevant.) My problem is that if I want to just have NaN's and Inf's propagated through, then in every calculation I need to do something like: # At the top of the module nan = float("nan") inf...

How do I install pycurl for python2.6 (CentOS 5)

Hi all, I can't install pycurl for python 2.6 on my server run CentOS 5. I use easy_install-2.6, but it output many errors. output here: http://pastebin.com/Dw92H7fC Help would be great. : ) ...

How to get 'Message-ID' using imaplib

I try to get an unique id that's not change during operation. I think UID is not good. So I think 'Message-ID' is the right thing, But I don't know how to get it. I know just imap.fetch(uid, 'XXXX'), Anyone has a solution?. ...

Python xlrd data extraction

I am using python xlrd http://scienceoss.com/read-excel-files-from-python/ to read data from an excel sheet My question is if i read a row with first cell as "Employee name" in the excel sheet And there is another row named whose first cell is "Employee name" How can we read the last column starting with the last row which has "Employ...

Django and Python + uWSGI

Using instruction I try to connect Python + uWSGI. I made default project in a folder /home/sanya/django/pasteurl. However, have opened it in a browser I get uWSGI Error wsgi application not found Logs contain the following: binding on TCP port: 9001 your server socket listen backlog is limited to 64 connections added /home/sanya/dj...

Fourier space filtering

I have a real vector time series x of length T and a filter h of length t << T. h is a filter in fourier space, real and symmetric. It is approximately 1/f. I would like to filter x with h to get y. Suppose t == T and FFT's of length T could fit into memory (neither of which are true). To get my filtered x in python, I would do: impor...

google app engine blob store creation.

In order to save precious bandwidth, the image serving app (a minor, but important part of the total app) tries to serve only thumbnails or reduced size previews of possibly large photos or illustrations. Storing the original image in the BlobStore is simple enough, and generating the thumbnails is also simple using the the Image servic...

How to add key,value pair to dictionary?

Hi Friends, How to add key,value pair to dictionary?.Below i have mentioned following format? {'1_somemessage': [[3L, 1L, u'AAA', 1689544L, datetime.datetime(2010, 9, 21, 22, 30), u'gffggf'], [3L, ...

Is this a memory leak?

I'm using gc module to debug a leak. It's a gui program and I've hooked this function to a button. I've set set debug more to gc.SAVE_ALL > gc.collect() > > print gc.garbage and this is the output [(<type '_ctypes.Array'>,), {'__module__': 'ctypes._endian', '__dict__': <attribute '__dict__' of 'c_int_Array_3' objects>, '__weakr...

Python: How use constants for multiple clasess?

Hi! I want use a constant in Python for 2 classes. Which is the better way? Thanks in advance! MY_COLOR = "#000001" # <-------- Are correct here? BLACK = "#000000" # <-------- Are correct here? class One: MY_FONT = "monospace" def __init__(self): if MY_COLOR == BLACK: print("It's black") if sel...

Can Django use "external" python scripts linked to other libraries (NumPy, RPy2...)

Dear all, I am new to the world of IT business (serious) development but I have in mind a business idea and still trying to vizualize how the overall infrastructure should work. I have done some few research for a good technology to deliver the solution. I am very inclined to use Python, MySql, Django (Apache) on the server side and so...

Right alignment for table cell in pyqt

I have QStandardItemModel and QTableView. I want to have the number align to the right. How can i specify this in pyqt? Now i have it like this (see ID) http://simple-database-explorer.googlecode.com/files/Main2.jpg Working example: self.model.setData(self.model.index(i, j, QtCore.QModelIndex()), value, role=0) if isNumber(value): ...

Shortest way to break-up long string (add whitespace) after 60 chars?

I'm processing a bunch of strings and displaying them on a web page. Unfortunately if a string contains a word that is longer than 60 chars it makes my design implode. Therefore i'm looking for the easiest, most efficient way to add a whitespace after every 60 chars without whitespaces in a string in python. I only came up with clunk...

Writing a module for both Python 2.x and 3.x

I've written a pure-Python module for Python 3.0/3.1 which I'd also like to make it compatible with 2.x (probably just 2.6/2.7) in order to make it available to the widest possible audience. The module is concerned with reading and writing a set of related file formats, so the differences between 2.x and 3.x versions would be slight — e...

multiple d-bus session bus objects in python

hi! I've written a script that connects to d-bus session bus on a remote computer like so: os.environ["DBUS_SESSION_BUS_ADDRESS"] = "tcp:host=192.168.0.1,port=1234" bus = dbus.SessionBus() That works fine except now I need to be able to connect to multiple session buses on different computers. I've tried the following: os.environ["D...

How to call a shell script from python code?

how to call a shell script from python code? ...

What is a good place to store configuration in Google AppEngine (python)

I am making a Google AppEngine application and am doubting were I should store (sensitive) configuration data like credentials. Should I make a single bigtable entity for configuration, or is there another advised way to store it. ...

Lightweight framework for forms w Ajax in Python

I'm new to Python and would like to know of some good framework / code library out there to help me out with building forms w/ ajax (and fallback to no-js) submits. Doing it from scratch is possible ofcourse, but since this is such a common task I figured there must be some great stuff out there. Django could be the way, but seems to b...

How to get IP when using SimpleXMLRPCDispatcher in Django

Having a code inspired from http://code.djangoproject.com/wiki/XML-RPC : from SimpleXMLRPCServer import SimpleXMLRPCDispatcher from django.http import HttpResponse dispatcher = SimpleXMLRPCDispatcher(allow_none=False, encoding=None) # Python 2.5 def rpc_handler(request): """ the actual handler: if you setup your urls.py pr...

Best way to create Singleton Table in Django/MySQL

I want a table which can only have one record. My current solution is: class HitchingPost(models.Model): SINGLETON_CHOICES = (('S', 'Singleton'),) singleton = models.CharField(max_length=1, choices=SINGLETON_CHOICES, unique=True, null=False, default='S'); value = models.IntegerField() def __unicode__(self): ret...