python

What is a Python egg?

Doing a quick search of SO, I didn't find anything, but feel free to just redirect me. Basically, I'm new to Python and just trying to understand how it's packages work. Presumably "eggs" are some sort of packaging mechanism, but if someone could give me a quick overview of what role they play and maybe some information on why they're ...

sqlite3 'database is locked' won't go away with retries

I have a sqlite3 database that is accessed by a few threads (3-4). I am aware of the general limitations of sqlite3 with regards to concurrency as stated http://www.sqlite.org/faq.html#q6 , but I am convinced that is not the problem. All of the threads both read and write from this database. Whenever I do a write, I have the following c...

Get HTML links within a specified <table> using minidom

Hi All - I'm looking to use Python and xml.dom.minidom to get a list of links within a particular <table> specified by the table id. Based on some excellent advice, I'm trying to use the DOM instead of pattern matching. import urllib import xml.dom.minidom url = 'http://www.batstrading.com/market_data/shortsales' page = xml.dom.minido...

PyQt4 Drag & Drop

Hi fellows! Qt4 has support for Drag & Drop actions and I've used them like in the tutorial. Now I want to be able to drag external elements (files) into the GUI form and perform actions based on that (like get the full path and copy it somewhere). I'm not sure whether this is a limitation like something Qt cannot do. Does someone kno...

"Optional" backreferences in regular expression

I'm not sure if my subject is correct but here is what I'm wanting to accomplish. I have a regular expression with two groups that are OR'd and I'm wondering if it's possible to have a group be a back reference only if it matched? In all cases, I'm wanting to match spam.eggs.com Example: import re monitorName = re.compile(r"HQ01 : HTT...

django combine models.DecimalField with forms -> error: quantize result has too many digits for current context

Hi, I want to combine a model decimal field with a forms choice field. The field in the model: sum = models.DecimalField(max_digits=2, decimal_places=2) The field in the form: sum = forms.ChoiceField(choices=WORK_HOUR_CHOICES, label='Sum Working Hours', required=True) The choices: WORK_HOUR_CHOICES = ( (0, '0'), (0.5, '0...

PyPlot reverse Y-Axis

I have a scatter plot graph with a bunch of random x,y coordinates. Currently the Y-Axis starts at 0 and goes up to the max value. I would like the Y-Axis to start at the max value and go up to 0. points = [(10,5), (5,11), (24,13), (7,8)] x_arr = [] y_arr = [] for x,y in points: x_arr.append(x) y_arr.append(y) plt.scatter(x_...

How to remove expired items from database with Scrapy

I am using spidering a video site that expires content frequently. I am considering using scrapy to do my spidering, but am not sure how to delete expired items. Strategies to detect if an item is expired are: Spider the site's "delete.rss". Every few days, try reloading the contents page and making sure it still works. Spider every ...

creating 2 foreign keys that relate to one another

class Product(models.Model): name = models.CharField(max_length = 127) description = models.TextField() code = models.CharField(max_length = 127) def __unicode__(self): return self.name class ProductLot(models.Model): product = models.ForeignKey(Product) code = models.ForeignKey(Product) l...

access to gnome configuration information using python

Is there a standard way of accessing Gnome configuration information (i.e. ~/.gconf) using Python? Updated: please provide a short example. ...

Python parallel processing libraries

Python seems to have many different packages available to assist one in parallel processing on an SMP based system or across a cluster. I'm interested in building a client server system in which a server maintains a queue of jobs and clients (local or remote) connect and run jobs until the queue is empty. Of the packages listed above, ...

Downgrading to pyobjc 2.0 from pyobjc 2.2

I accidentally installed pyobjc 2.2 with easy-install pyobjc, and it's causing problems: When I try to import it I get the error Incompatible library version: _objc.so requires version 10.0.0 or later, but libxml2.2.dylib provides version 9.0.0 I'm not interested in fixing that though, all I want is my pyobjc 2.0 back. I've tried rem...

Efficient way to either create a list, or append to it if one already exists?

I'm going through a whole bunch of tuples with a many-to-many correlation, and I want to make a dictionary where each b of (a,b) has a list of all the a's that correspond to a b. It seems awkward to test for a list at key b in the dictionary, then look for an a, then append a if it's not already there, every single time through the tupl...

How to use a Django include tag for a separate HTML template?

I am trying to use the include Django template tag, and inside it I reference a template which handles the format of the form. When I reference this though inside my template it outputs each of the dynamic parts, each character per new line, it is really strange. For example here is a snippet of the output: <form action="/admin/events...

Threading in a django app

I'm trying to create what I call a scrobbler. The task is to read a Delicious user from a queue, fetch all of their bookmarks and put them in the bookmarks queue. Then something should go through that queue, do some parsing and then store the data in a database. This obviously calls for threading because most of the time is spent waitin...

How to throttle Django error emails.

I use django error reporting via email. It is normally a very helpful feature, except that now we have 5 minutes of database downtime and I got 2000 emails. Is there any middleware that will help me throttle the number of emails django can send out per minute? ...

Updating the wx.gauge without while-loop

Have been wondering about this for days now: I have a basic wxpython program like this: from MyModule import * class Form(wx.Panel): def __init__(self, parent, id): self.gauge = wx.Gauge(...) ... def ButtonClick(self, event): proc = LongProcess() while (LongProcess): self.gauge.SetValue(LongProcess.status) ...

How do I manually throw/raise an exception in python?

I want to make an error on purpose so that it would go into the "except": How do i do that? ...

Problem assigning input to list

I know this is probably an easy question but after reviewing the documentation for python 2.6.4 I cannot seem to find out what is wrong. This is my file, in it's entirety. The problem I am having is in get_phone_number(). After asking for the amount of phone numbers, I get this error: Traceback (most recent call last): File "/home/cha...

Uploading files to App Engine using webapp and Django forms

My basic question is this: Is there an equivalent of form = MyForm(request.POST, request.FILES) when handling file uploads using the webapp framework on Google App Engine? I know that I can pull out specific uploaded file data using self.request.get('field_name') or a FieldStorage object using self.request.params['field_name'], but...