python

pygtk: How to set the height of pop-up window in gtk.EntryCompletion

I use gtk.EntryCompletion to implement the autocomletion function. But the list is so long that the pop-up window touches the bottom of screen. And I cant find the method of set the height of pop-up window in doc of pygtk. How to set the height of pop-up window in gtk.EntryCompletion? ...

How to spawn multiple python scripts from a python program ?

Hi I want to spawn (fork?) multiple Python scripts from my program (written in Python too) My problem is that I want to dedicate one terminal to each script , because I'll gather their output using pexpect. I've tried using pexpect, os.execlp and os.forkpty but neither of them do as I expect. I want to spawn the child processes and forge...

Python Generator - what not to use it for

Just looking at Python generators, real impressed with them, but are there any things not to use them for? I was thinking of past C coding where reading from a file, or user actions would be areas. For example, could the generator be used to prompt the user for input (base data entry?) and the calling function process that input? are t...

python logarithm

i want to find out a log10 of an integer in python and i get an error like math domain error my code is this w=math.log10(q*q1)/math.log10(2) where q1,q2 are integers yeah q1 is 0 sometimes ...

How can I speed up a web-application? (Avoid rebuilding a structure.)

After having successfully build a static data structure (see here), I would want to avoid having to build it from scratch every time a user requests an operation on it. My naïv first idea was to dump the structure (using python's pickle) into a file and load this file for each query. Needless to say (as I figured out), this turns out to ...

Module to produce RSS from Python

Possible Duplicate: Recommended Python RSS/Atom feed generator? The Universal Feed Parser can read feeds, but anything similar for writing different types of feeds (RSS x.x, Atom, etc)? Or do I just have to bite the bullet and hand-produce the XML? ...

How to enumerate a list of non-string objects in Python?

There is a nice class Enum from enum, but it only works for strings. I'm currently using: for index in range(len(objects)): # do something with index and objects[index] I guess it's not the optimal solution due to the premature use of len. How is it possible to do it more efficiently? ...

Making a plain ASCII/UTF-8 request/stream HTTP POST request in Python?

I'm reading some documentation on a service I'm trying to use, and it reads something like this: All requests must be sent using HTTP Post. The XML engine only accepts plain ASCII (text) UTF-8 requests/streams. Encoded streams are not acceptable. All requests/responses are XML. But I really just don't understand what it's a...

Bazaar: Modify file content before commit via hook?

Hi folks, I'm switching from SVN to Bzr for my private projects. There is one feature missing for me, which SVN provides: The replacement of a $Id:$ placeholder with the latest version identification. So far, Bzr provides hooks to do some tricks within the commit process. I've managed to get a list of modified files an manipulate them o...

Instance methods called in a separate thread than the instantiation thread

I'm trying to wrap my head around what is happening in this recipe, because I'm planning on implementing a wx/twisted app similar to this (ie. wx and twisted running in separate threads). I understand that both twisted and wx event-loops need to be accessed in a thread-safe manner (ie. reactor.callFromThread, wx.PostEvent, etc). What I...

How to use numpy with 'None' value in python?

Hello everybody, i'm a pretty new user of python and numpy, so i hope my question won't annoy you. Well, i'd like to calculate the mean of an array in python in this form : Matrice = [1, 2, None] I'd just like to have my None value ignored by the numpy.mean calculation but i can't figure out how to do it. If anybody can help me tha...

How can I speed up update/replace operations in PostgreSQL?

We have a rather specific application that uses PostgreSQL 8.3 as a storage backend (using Python and psycopg2). The operations we perform to the important tables are in the majority of cases inserts or updates (rarely deletes or selects). For sanity reasons we have created our own Data Mapper-like layer that works reasonably well, but...

How to pull a random record using Django's ORM?

I have a model that represents paintings I present on my site. On the main webpage I'd like to show some of them: newest, one that was not visited for most time, most popular one and a random one. I'm using Django 1.0.2. While first 3 of them are easy to pull using django models, last one (random) causes me some trouble. I can ofc cod...

PyQt - QLabel inheriting

Hello, i wanna inherit QLabel to add there click event processing. I'm trying this code: class NewLabel(QtGui.QLabel): def __init__(self, parent): QtGui.QLabel.__init__(self, parent) def clickEvent(self, event): print 'Label clicked!' But after clicking I have no line 'Label clicked!' EDIT: Okay, now I'm usi...

How to call up attributes in python 3.1 -- easy

Python 2.5 all you needed to do was type "dir(filename)" and that pulls up the attributes. What is the command in 3.1? ...

Python: changing methods and attributes at runtime

I wish to create a class in Python that I can add and remove attributes and methods. How can I acomplish that? Oh, and please don't ask why. ...

How can I create a variable that is scoped to a single request in app engine?

I'm creating a python app for google app engine and I've got a performance problem with some expensive operations that are repetitive within a single request. To help deal with this I'd like to create a sort of mini-cache that's scoped to a single request. This is as opposed to a session-wide or application-wide cache, neither of which...

Python display string multiple times

I want to print a character or string like '-' n number of times. Can I do it without using a loop?.. Is there a function like print('-',3) ..which would mean printing the - 3 times, like this: --- ...

how to use session/cookie in twisted.web?

Hi everyone, I am implementing an http server with twisted.web. Here comes the problem: there is a login operation; after that, I want the http server to remember each client using acookie/session, until the user closes the browser. I've read the twisted.web document, but I can't figure out how to do this. I know the request objec...

Python Library/Framework for writing P2P applications

Is there any library or framework for writing P2P applications in Python ? I know the initial Bittorrent client was written in Python. I'm looking something like JXTA but for Python. ...