python

Running a function periodically in twisted protocol

I am looking for a way to periodically send some data over all clients connected to a TCP port. I am looking at twisted python and I am aware of reactor.callLater. But how do I use it to send some data to all connected clients periodically ? The data sending logic is in Protocol class and it is instantiated by the reactor as needed. I do...

OpenCV's Python - OS X

I get the following error while building OpenCV on OS X 10.5 (intel): ld: warning in .libs/_cv_la-_cv.o, file is not of required architecture ld: warning in .libs/_cv_la-error.o, file is not of required architecture ld: warning in .libs/_cv_la-pyhelpers.o, file is not of required architecture ld: warning in .libs/_cv_la-cvshadow.o, file...

python float to Decimal conversion

Python Decimal doesn't support being constructed from float, it expects that you have to convert float to a string first. This is very inconvenient since standard string formattors for float require that you specify number of decimal places rather than significant places. So if you have a number that could have as many as 15 decimal ...

Which programming language to learn now?

Possible Duplicate: Which Programming Language Should I Learn? So I recently just finished a year of Java in my Computer Science class, and want to further pursue programming. I was not much thrilled about Java, I liked the OOP part but disliked its execution speed. I was thinking C++ but I keep hearing people complain (?) ab...

"import wx" fails after installation of wxPython on Windows XP

I downloaded and installed this version of wxPython for use with my Python 2.6 installation: http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.9.1-py26.exe When I run Python and try to import wx, I get the following error: C:\Program Files\Console2>python Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 ...

Is there a good NumPy clone for Jython?

I'm a relatively new convert to Python. I've written some code to grab/graph data from various sources to automate some weekly reports and forecasts. I've been intrigued by the Jython concept, and would like to port some Python code that I've written to Jython. In order to do this quickly, I need a NumPy clone for Jython (or Java). I...

Problem compiling MySQLdb for Python 2.6 on Win32

I'm using Django and Python 2.6, and I want to grow my application using a MySQL backend. Problem is that there isn't a win32 package for MySQLdb on Python 2.6. Now I'm no hacker, but I thought I might compile it myself using MSVC++9 Express. But I run into a problem that the compiler quickly can't find config_win.h, which I assume is...

Ghostscript PDF -> TIFF throws an untrappable exception, when consuming files with asian fonts

Ghostscript curls up and dies, throwing an exception to stdout which I cannot catch and log. I am pretty sure it gets sick when I give it asian fonts. Has anybody backed into this problem and solved it? ...

Python Screenscraping

I'm wanting to create a REST API for TV listings in my country. While online aggregations of TV listings do exist they're too tied to the presentation to be of any use to software developers. In order to get hold of this information I'm thinking of going to each source and scraping the relevant information. While I've obtained similar i...

Ping a site in Python?

The basic code is: from Tkinter import * import os,sys ana= Tk() def ping1(): os.system('ping') a=Button(pen) ip=("192.168.0.1") a.config(text="PING",bg="white",fg="blue") a=ping1.ip ??? a.pack() ana.mainloop() How could I ping a sites or address? ...

Newbie Python question about strings with parameters: "%%s"?

I'm trying to figure out what the following line does exactly - specifically the %%s part? cursor.execute('INSERT INTO mastertickets (%s, %s) VALUES (%%s, %%s)'%sourcedest, (self.tkt.id, n)) Any good mini-tutorial about string formatting and inserting variables into strings with Python? ...

Get Element value with minidom, Python

Hi Guys, I am creating a GUI frontend for the Eve Online API in Python. I have successfully pulled the XML data from their server. I am trying to grab the value from a node called "name" from xml.dom.minidom import parse dom = parse("C:\\eve.xml") name = dom.getElementsByTagName('name') print name This seems to find the node ok but...

Python: packing an ip address as a ctype.c_ulong() for use with DLL

given the following code: import ctypes ip="192.168.1.1" thisdll = ctypes.cdll['aDLL'] thisdll.functionThatExpectsAnIP(ip) how can I correctly pack this for a DLL that expects it as a c_ulong datatype? I've tried using: ip_netFrmt = socket.inet_aton(ip) ip_netFrmt_c = ctypes.c_ulong(ip_netFrmt) however, the c_ulong() method ...

Standard C or Python libraries to compute standard deviation of normal distribution.

Say we have normal distribution n(x): mean=0 and \int_{-a}^{a} n(x) = P. What is the easiest way to compute standard deviation of such distribution? May be there are standard libraries for python or C, that are suitable for that task? ...

Best book to learn python?

I've never developed on python.. Can you please tell me what is the best book to learn how to program in python? Thanks a lot DUPLICATE: http://stackoverflow.com/questions/143397/booksweb-sites-recommendation-for-learning-python ...

Python: converting strings for use with ctypes.c_void_p()

given a string: msg="hello world" How can I define this as a ctypes.c_void_p() data type? the following code yields a "cannot be converted to pointer" exception: data=ctypes.c_void_p(msg) data is required to be a void* type in C, because it is being passed to a DLL. I'm assuming there is a way to pack/unpack the string using the...

Running numpy from cygwin

I am running a windows machine have installed Python 2.5. I also used the windows installer to install NumPy. This all works great when I run the Python (command line) tool that comes with Python. However, if I run cygwin and then run Python from within, it cannot find the numpy package. What environment variable do I need to set? W...

Does anyone know where there is a recipe for serializing data and preserving its order in the output?

I am working with a set of data that I have converted to a list of dictionaries For example one item in my list is {'reportDate': u'R20070501', 'idnum': u'1078099', 'columnLabel': u'2005', 'actionDate': u'C20070627', 'data': u'76,000', 'rowLabel': u'Sales of Bananas'} Per request The second item in my list could be: {'reportDat...

Problem with relative path in Python

I know this is a simple, beginner-ish Python question, but I'm having trouble opening a file using a relative path. This behavior seems odd to me (coming from a non-Python background): import os, sys titles_path = os.path.normpath("../downloads/movie_titles.txt") print "Current working directory is {0}".format(os.getcwd()) print "Titl...

Asynchronous file writing possible in python?

Is there an existing module or an easy way to use aio_write to write to a file asynchronously in python? I know by file io that comes with Python is all blocking which is fine in most cases, but for this particular case I need writes not to block the application at all, or at least as minimally as possible. ...