python

convert byte array to string without interpreting the bytes?

Hi I have a GSM date/time stamp from a PDU encoded SMS it is formatted as so \x90,\x21,\x51,\x91,\x40,\x33 format yy,mm,dd,hh,mm,ss I have read them from a binary file into a byte array. I want to convert them to a string but without doing any decoding I want to end up with a string that contains 902151914033. I then need to reverse ...

Filter zipcodes by proximity in Django with the Spherical Law of Cosines

I'm trying to handle proximity search for a basic store locater in Django. Rather than haul PostGIS around with my app just so I can use GeoDjango's distance filter, I'd like to use the Spherical Law of Cosines distance formula in a model query. I'd like all of the calculations to be done in the database in one query, for efficiency. A...

How to pass value for python for loop?

In C/C++: for(int i=0;i<=5;i++) In Python: for i in range(0,5) Question is: s=[1,2,3,4,1] for i in s: for j in s: Here i wanna make second for loop j=1 (j value should be start with 1 like this s[1]=2).How do i pass that value. ...

How to store a dynamic List into MySQL column efficiently?

I want to store a list of numbers along with some other fields into MySQL. The number of elements in the list is dynamic (some time it could hold about 60 elements) Currently I'm storing the list into a column of varchar type and the following operations are done. e.g. aList = [1234122433,1352435632,2346433334,1234122464] At storing ...

Python stack for data centric scalable REST application

What Python frameworks/libraries you would use to create a data centric REST application. The application will have the following traits: read-biased in terms of number of individual ad-hoc requests write-biased in number of records added in batch feeds scalable (think virtual appliance, cloud) variety of data formats such as csv files...

Installing Fabric On Windows (Error No Module Called Readline)

I'm trying to use the Fabric 0.1.1 deploy tool (http://docs.fabfile.org/) on Windows and we're running into an issue with the readline module. I've been through various threads but can't seem to solve the issue. It's important because we can't deploy applications from Windows based machines. C:\Documents and Settings\dev\Desktop\deplo...

How to launch a Python/Tkinter dialog box that self-destructs?

Ok, I would like to put together a Python/Tkinter dialog box that displays a simple message and self-destructs after N seconds. Is there a simple way to do this? Thanks, --Steve ...

Control decimal division precision in MySQLdb

MySQLdb does some weirdness where it seems to always return a Decimal object with 2 more significant figures than the numerator of a division operation. If the denominator is relatively large, this means that sometimes the result gets truncated to zero: >>> import MySQLdb >>> db = MySQLdb.connect(.....) >>> c = db.cursor(); >>> c.execu...

Calling a function this way would be bad style?

Suppose I have this function signature: def foo(a=True, b=True, c=True, d=True, e=True): I've decided these would be concise ways to call this function, considering all passed parameters should be False: foo(*5*[False]) foo(*[False]*5) But something tells me that would be bad Python style. What do you think? ...

Relational Programming in Python?

Hi all, I'm a longtime python developer and recently have been introduced to Prolog. I love the concept of using relations for certain kinds of tasks, and would like to add this to my repertoire. Are there any good libraries for relational programming in Python? I've done some searching on Google but only found the following: http:/...

Perl within Python?

There is a Perl library I would like to access from within Python. How can I use it? FYI, the software is NCleaner. I would like to use it from within Python to transform an HTML string into text. (Yes, I know about aaronsw's Python html2text. NCleaner is better, because it removes boiler-plate.) I don't want to run the Perl program as...

Python joining strings

I have run into a problem joining two strings in Python. I have some code that is like this: for line in sites: site = line for line in files: url = site+line That should be easy I thougth but the strings ends up "looking wierd": http://example.com/ (this is the site) history.txt (Then the line come...

When using py2app, is there a way to customize the traceback dialog that gets displayed? (Or show a different Cocoa dialog?)

Is there an easy way to get any more control over the py2app traceback dialogs, or just a nice way to display GUI messages? If I raise an exception in my py2app script, I get a dialog that says something like this: MyAppName Error MyAppName Error An unexpected error has occurred during execution of the main script MyR...

Python import mechanics

I have two related Python 'import' questions. They are easily testable, but I want answers that are language-defined and not implementation-specific, and I'm also interested in style/convention, so I'm asking here instead. 1) If module A imports module B, and module B imports module C, can code in module A reference module C without an...

Making python/tkinter label widget update?

I'm working on getting a python/tkinter label widget to update its contents. Per an earlier thread today, I followed instructions on how to put together the widgets. At runtime, however, the label widget does NOT change contents, but simply retains its original content. As far as I can tell, decrement_widget() is never called at all. Any...

Auth_token error at Facebook

i have been on this for the last 2 days with no result. i am running my facebook app on my localhost with port-forwarding method. i know my server setup is working fine as i can see the logs on the django runserver and dyndns log as well. django is properly responding to calls as well. the problem is as soon as the app authorizes with ...

Python lists append return value

I wanted to create a simple binary tree as followed by this image: http://imgur.com/QCVSW.png basically empty , but the last values so I created the root list : root = [list(),list()] and made a recursive function to populate it all : def TF(nodeT,nodeF , i): if i == 35 : return 'done' TF(nodeT.append([]),nodeT.append([])...

split a pdf based on outline

i would like to use pyPdf to split a pdf file based on the outline where each destination in the outline refers to a different page within the pdf. example outline: main --> points to page 1 sect1 --> points to page 1 sect2 --> points to page 15 sect3 --> points to page 22 it is easy within pyPdf to iterate ove...

What is a hashtable/dictionary implementation for Python that doesn't store the keys?

I'm storing millions, possibly billions of 4 byte values in a hashtable and I don't want to store any of the keys. I expect that only the hashes of the keys and the values will have to be stored. This has to be fast and all kept in RAM. The entries would still be looked up with the key, unlike set()'s. What is an implementation of this ...

Can anyone explain python's relative imports?

Hello, I can't for the life of me get python's relative imports to work. I have created a simple example of where it does not function: The directory structure is: /__init__.py /start.py /parent.py /sub/__init__.py /sub/relative.py /start.py contains just: import sub.relative /sub/relative.py contains just from .. import parent All...