python

Python int -> binary?

Am I reading this right? There aren't any canned Python methods to convert an Integer (or Long) into a binary string in Python? There are a myriad of dec2bin() functions out on Google... But I was hoping I could use a built-in function / library. ...

Format a number as a string

How do you format a number as a string so that it takes a number of spaces in front of it? I want the shorter number 5 to have enough spaces in front of it so that the spaces plus the 5 have the same length as 52500. The procedure below works, but is there a built in way to do this? a = str(52500) b = str(5) lengthDiff = len(a) - len(...

communication with long running tasks in python

I have a python GUI app that uses a long running function from a .so/.dll it calls through ctypes. I'm looking for a way to communicate with the function while it's running in a separate thread or process, so that I can request it to terminate early (which requires some work on the C side before returning a partial result). I suppose th...

Is there a Python library to interact with Genesys?

I work within a contact center and we use Genesys with an Alcatel PBX. We currently use .NET libraries to wrap the DLL's provided to us, but I'm wondering if there are any Python libraries out there before I attempt to write my own? Thanks ...

How to add a Python import path using a .pth file

If I put a *.pth file in site-packages it's giving an ImportError. I'm not getting how to import by creating a *.pth file. (Refers to importing in python) ...

Control access to WebDav/Apache using Python

I want to give users access to WebDav using Apache, but I want to autenticate them first and give each user access to a specific folder. All authentication must be done against a Django-based database. I can get the Django-authentication working myself, but I need help with the part where I authenticate each user and provide them with a ...

How to detect changed and new items in an RSS feed?

Using feedparser or some other Python library to download and parse RSS feeds; how can I reliably detect new items and modified items? So far I have seen new items in feeds with publication dates earlier than the latest item. Also I have seen feed readers displaying the same item published with slightly different content as seperate ite...

EOFError in Python script

I have the following code fragment: def database(self): databasename="" host="" user="" password="" try: self.fp=file("detailing.dat","rb") except IOError: self.fp=file("detailing.dat","wb") pickle.dump([databasename,host,user,password],self.fp,-1) self.fp.close() selffp=f...

How to design multi-threaded GUI-network application?

I'm working on a small utility application in Python. The networking is gonna send and recieve messages. The GUI is gonna display the messages from the GUI and provide user input for entering messages to be sent. There's also a storage part as I call it, which is gonna get all the network messages and save them in some kind of database...

Py3k memory conservation by returning iterators rather than lists

Many methods that used to return lists in Python 2.x now seem to return iterators in Py3k Are iterators also generator expressions? Lazy evaluation? Thus, with this the memory footprint of python is going to reduce drastically. Isn't it? What about for the programs converted from 2to3 using the builtin script? Does the builtin tool e...

Is there a standard 3rd party Python caching class?

I'm working on a client class which needs to load data from a networked database. It's been suggested that adding a standard caching service to the client could improve it's performance. I'd dearly like not to have to build my own caching class - it's well known that these provide common points of failure. It would be far better to use...

Best way to choose a random file from a directory

What is the best way to choose a random file from a directory in Python? Edit: Here is what I am doing: import os import random import dircache dir = 'some/directory' filename = random.choice(dircache.listdir(dir)) path = os.path.join(dir, filename) Is this particularly bad, or is there a particularly better way? ...

Library/tool for drawing ternary/triangle plots

I need to draw ternary/triangle plots representing mole fractions (x, y, z) of various substances/mixtures (x + y + z = 1). Each plot represents iso-valued substances, e.g. substances which have the same melting point. The plots need to be drawn on the same triangle with different colors/symbols and it would be nice if I could also conne...

Nested try statements in python?

Is there a nicer way of doing the following: try: a.method1() except AttributeError: try: a.method2() except AttributeError: try: a.method3() except AttributeError: raise It looks pretty nasty and I'd rather not do: if hasattr(a, 'method1'): a.method1() else if hasattr(a...

How do you convert HTML entities to Unicode and vice versa in Python?

Duplicate: Convert XML/HTML Entities into Unicode String in Python How do you convert HTML entities to Unicode and vice versa in Python? ...

Is there a python library that implements both sides of the AWS authentication protocol?

I am writing a REST service in python and django and wanted to use Amazon's AWS authentication protocol. I was wondering if anyone knew of a python library that implemented formation of the header for sending and the validation of the header for recieving? ...

How do I execute a string containing Python code in Python?

How do I execute a string containing Python code in Python? ...

Django Model.object.get pre_save Function Weirdness

Hello! I have made a function that connects to a models 'pre_save' signal. Inside the function I am trying to check if the model instance's pk already exists in the table with: sender.objects.get(pk=instance._get_pk_val()) The first instance of the model raises an error. I catch the error and generate a slug field from the title. In a...

Django vs other Python web frameworks?

I've pretty much tried every Python web framework that exists, and it took me a long time to realize there wasn't a silver bullet framework, each had its own advantages and disadvantages. I started out with Snakelets and heartily enjoyed being able to control almost everything at a lower level without much fuss, but then I discovered Tur...

How to get number of affected rows in sqlalchemy?

Hi everybody, I have one question concerning Python and the sqlalchemy module. What is the equivalent for cursor.rowcount in the sqlalchemy Python? Thank you ...