python

Python: Can a class forbid clients setting new attributes?

I just spent too long on a bug like the following: >>> class Odp(): def __init__(self): self.foo = "bar" >>> o = Odp() >>> o.raw_foo = 3 # oops - meant o.foo I have a class with an attribute. I was trying to set it, and wondering why it had no effect. Then, I went back to the original class definition, and saw that the a...

Shutting down gracefully from ThreadingTCPServer

I've created a simple test app (Python 2.6.1) that runs a ThreadingTCPServer, based on the example here. If the client sends a command "bye" I want to shut down the server and exit cleanly from the application. The exit part works OK, but when I try to re-run the app, I get: socket.error: [Errno 48] Address already in use I tried th...

Using Python's @property decorator on dicts

I'm trying to use Python's @property decorator on a dict in a class. The idea is that I want a certain value (call it 'message') to be cleared after it is accessed. But I also want another value (call it 'last_message') to contain the last set message, and keep it until another message is set. In my mind, this code would work: >>> class...

Is this correct way to import python scripts residing in arbitrary folders?

This snippet is from an earlier answer here on SO. It is about a year old (and the answer was not accepted). I am new to Python and I am finding the system path a real pain. I have a few functions written in scripts in different directories, and I would like to be able to import them into new projects without having to jump through hoops...

python project idea

I understand that there are tons of similar questions here and I also understand that the "correct" answer is whatever motivates you. However, I always have trouble generating ideas. Sometimes, I sit for hours coming up with nothing (I am not exaggerating) and I just end up wasting time. I've found that my main motivation is this: I ca...

Is it possible to use readline instead of libedit in Python's raw_input under OS X?

From the readline module documentation, it mentions: On MacOS X the readline module can be implemented using the libedit library instead of GNU readline. The configuration file for libedit is different from that of GNU readline. Is it possible to use the readline library in /usr/lib/libreadline.dylib for example, or even compiled w...

Unescaping HTML in Django

I have html encoded text which reads like this: RT <a href="http://twitter.com/freuter"&gt;@freuter&lt;/a&gt;... I want this displayed as html but I am not sure if there is a filter which i can apply to this text to convert the html-encoded text back to html ... can someone help? ...

Optimising memory usage in numpy

The following program loads two images with PyGame, converts them to Numpy arrays, and then performs some other Numpy operations (such as FFT) to emit a final result (of a few numbers). The inputs can be large, but at any moment only one or two large objects should be live. A test image is about 10M pixels, which translates to 10MB onc...

In Eclipse PyDev is there a way to exclude arbitrary file-types from the Pydev Package explorer?

If you click on the icon resembling a downard-pointing triangle in the PyDev Package Explorer and then select "Customize View", The "Available Customizations" pop-down allows the user to select which of a standard set of files are visible in the package explorer. That's great if you wish to exlude or include certain standard types of f...

Python - passing object references ?

Hi I learning Python (coming from a dotnet background) and developing an app which interacts with a webservice. The web service is flat, in that it has numerous calls some of which are related to sessions e.g. logging on etc, whereas other calls are related to retrieving/setting business data. To accompany the webservice, there are ...

Pylons + SQLAlchemy problem: The transaction is inactive due to a rollback in a subtransaction

I have a problem with Pylons + SQLAlchemy. When something goes wrong (in my case it is integrity error, due to a race condition) and the database error is raised, all following requestы result in the error being raised: InvalidRequestError: The transaction is inactive due to a rollback in a subtransaction. Issue rollback() to cancel t...

Installing django with python 2.5 and not with the default version of python.

Hi all, I have to install Django on my linux server where python 2.4 is available as the default installation. I have installed python 2.5 as a separate version. Now I have to install Django which I have to use with python 2.5. Is there any specific requirement, so that it is installed with the python 2.5 and not with the default 2.4 ve...

How to select following sibling/xml tag using xpath

I have an HTML file (from Newegg) and their HTML is organized like below. All of the data in their specifications table is 'desc' while the titles of each section are in 'name.' Below are two examples of data from Newegg pages. <tr> <td class="name">Brand</td> <td class="desc">Intel</td> </tr> <tr> <td class="name">Series</...

Qt programming: More productive in Python or C++?

Trying to dive into Qt big time but haven't done a large project with it yet. Currently using Python, but I've been thinking -- which is really the better language to use in terms of programmer productivity? In most comparisons between the languages, Python is the obvious answer, because you don't have to mess with memory management and...

Is it possible to debug CherryPy applications?

Hey All, I've seen this question posted here before but I want to get a final yes/no on this. I've been trying to debug my app using Netbeans 6.8 (no luck at all) and the newly released Netbeans 6.9 (notices that code has been called but fails to stop the code from executing). Is it possible to debug CherryPy applications? ...

Python limited multithreading

Hi all, As you surely know, I can do multithreading to download files from the Internet faster. But if I send lots of requests to the same website, I could be black listed. So could you help me to implement something like "I've got a list of urls. I want you to download all of these files but if 10 downloads are already running, wait ...

Feedback wanted for my first django custom field!

Hi I've created my first custom django field. Its a social security number field (Cpr) following danish syntax. As I'm new to both python and django i would love to get some feedback on the code! import django.forms as f from datetime import datetime import json from django.utils.safestring import mark_safe from django.core.exceptions i...

timeit module hangs with bigger values of pow()

Dear All, I am trying to calculate the time taken by pow function to calculate exponential modulo. With the values of g,x,p hardcoded the code gives error and with the values placed in the pow function, the code hangs. The same piece of code is working efficiently when i am using time() and clock() to calculate the time taken by this pi...

Python - Reportlab: Error using custom font

Im using the reportlab framework for creating pdf's. I'm also using a custom font in my pdf's called '3of9'. Now, sometimes I'm getting the following error: IOError: Cannot open resource "/usr/lib/python2.6/site-packages/reportlab/fonts/LeERC___.AFM", while looking for faceName='3of9' This doesn't happens everytime, but too often. And ...

Python GStreamer webcam viewer

Dear all, I'working on this nice example that shows a webcam output in a GTK widget with python and GStreamer: http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html here is the code: #!/usr/bin/env python import sys, os import pygtk, gtk, gobject import pygst pygst.require("0.10") import gst class GTK_Main: def __init__(sel...