python

install ImageUtils python

I am trying to install ImageUtils, I found the package but it doesn't have an installer with it. what is the procedure? ...

starting protocol in python with dameon + dbus

I've defined some protocol messages and every works on his own. These messages now needs to be connected. I think it will be all in a function called in the dameon mainloop or via DBus. The problems are: - threading is not allowed - the protocoll must be stateless - callable from a DBusInterface - also running on a daemon, that is the...

Verify a file exists over ssh

Hello, I am trying to test if a file exists over SSH using pexpect. I have got most of the code working but I need to catch the value so I can assert whether the file exists. The code I have done is below: def VersionID(): ssh_newkey = 'Are you sure you want to continue connecting' # my ssh command line p=pexpe...

Python: Creating a streaming gzip'd file-like?

I'm trying to figure out the best way to compress a stream with Python's zlib. I've got a file-like input stream (input, below) and an output function which accepts a file-like (output_function, below): with open("file") as input: output_function(input) And I'd like to gzip-compress input chunks before sending them to output_func...

Is there a better way to convert from decimal to binary in python?

I need to convert from an integer to a list of size 8 that is the binary representation of that number (number <= 255) and back. Currently I am using these lines list(bin(my_num)[2:].rjust(8,'0')) int("".join(my_list),2) I did some googling, but had a hard time finding relevant information. I'm just curious if there is a faster, or ...

Recommended Django setup?

I am about to embark a major django project. If I install the latest stable release... is the a suggested setup ie. this OS, this RDBMS, this version of python etc?? I'm normally a CentOS man but their repos don't play too well with the django requirements... ...

Html to image in javascript or python

Hi there. Just a dumb question... Is there any way you can create an image, say png, with the content of an html page, with a simple click of a button? Thanks to anyone who cares to answers. ...

How do Python's class closures work?

If I make a class against a local namespace, how exactly does it work? For instance: >>> def foo(): ... i = 1 ... class bar(object): ... j = i ... return bar ... >>> dis(foo) 2 0 LOAD_CONST 1 (1) 3 STORE_DEREF 0 (i) 3 6 LOAD_CONST 2...

Using explicit del in python on local variables

What are the best practices and recommendations for using explicit del statement in python? I understand that it is used to remove attributes or dictionary/list elements and so on, but sometimes I see it used on local variables in code like this: def action(x): result = None something = produce_something(x) if something: ...

Python: urllib2.urlopen(url, data) Why do you have to urllib.urlencode() the data?

I thought that a post sent all the information in HTTP headers when you used post (I'm not well informed on this subject obviously), so I'm confused why you have to urlencode() the data to a key=value&key2=value2 format. How does that formatting come into play when using POST?: # Fail data = {'name': 'John Smith'} urllib2.urlopen(foo_ur...

How to start a "drawing loop" in PyQt?

Often times when we're drawing a GUI, we want our GUI to update based on the data changing in our program. At the start of the program, let's say I've drawn my GUI based on my initial data. That data will be changing constantly, so how can I redraw my GUI constantly? ...

extend Python namedtuple with many @properties ?

How can namedtuples be extended or subclassed with many additional @properties ? For a few, one can just write the text below; but there are many, so I'm looking for a generator or property factory. One way would be to generate text from _fields and exec it; another would be an add_fields with the same effect at runtime. (My @props are t...

M2Crypto: AttributeError for load_dynamic_engine()

I am using M2Crypto-0.20.2. I want to use engine_pkcs11 from the OpenSC project and the Aladdin PKI client for token based authentication making xmlrpc calls over ssl. I am trying to load the PKCS#11 engine as well as the Aladdin module (see code below). But I get an error: AttributeError: 'module' object has no attribute 'load_dynami...

How to initialize a QT thread in python

As per examples seen online, I've created a Worker thread. I'm looking for a thread to run my GUI while one thread executes my code. Worker thread is defined as: class Worker(QThread): def __init__(self, parent = None): QThread.__init__(self, parent) self.exiting = False self.size = QSize(0, 0) def __...

Creating a video file from a group of PGM files in python

Hi My python program generates a collection of binary files. I create pgm (portable bitmap files) using this binary data. I would like to create a video using each of the pgm files as a frame in my video. I have had a look an mencoder but I dont think it supports pgm files Can anyone offer any advice. ...

Display function definition in interactive shell

I am working in the Python Interactive Shell (ActiveState ActivePython 2.6.4 under Windows XP). I created a function that does what I want. However, I've cleared the screen so I can't go back and look at the function definition. It is also a multiline function so the up arrow to redisplay lines is of minimal value. Is there anyway to ret...

How to connect to a LDAP server using a p12 certificate

I want to connect to a LDAP server using a .p12 certificate instead of using a username and password. The Java solution for this looks like String ldapURL = "ldaps://"+host+":"+port; System.setProperty("javax.net.ssl.keyStoreType", "PKCS12" ); System.setProperty("javax.net.ssl.keyStore",keystore); System.setProperty("javax.net.ssl...

How to launch a background process in Python with a delayed invocation?

Ok, this is a bit of a thorny problem. I need to launch a backgrounded process that will (1) wait N secs, and then (2) execute some command. Additionally, I need to capture the pid of the background process itself, because when the parent process finishes it will kill the backgrounded process if necessary. It looks a bit like this in she...

Python conversion to ISO-8859-5

I'm facing problems when trying to convert a UTF-8 file (containing Russian characters) into an ISO-8859-5 file: 'charmap' codec can't encode character u'\ufeff' in position 0: character maps to . Has anyone got an idea of what's wrong(?) given the following: def convert(): try: import codecs data = codecs.open('in.t...

catching SQLAlchemy exceptions

What is the upper level exception that I can catch SQLAlechmy exceptions with ? >>> from sqlalchemy import exc >>> dir(exc) ['ArgumentError', 'CircularDependencyError', 'CompileError', 'ConcurrentModificationError', 'DBAPIError', 'DataError', 'DatabaseError', 'DisconnectionError', 'FlushError', 'IdentifierError', 'IntegrityError', 'Inte...