python

A multithreaded queue in Python

I need to perform time consuming tasks in an webapplication. Because the tasks can be so heavy that they run for minutes they have to run on multiple threads so the user won't have to look at a loading page for minutes. So I thought a multithreaded queue would be a good solution. Each instance of a object that you add to the queue shoul...

What if setuptools isn't installed?

I'm just learning the art of writing a setup.py file for my project. I see there's lots of talk about setuptools, which is supposed to be superior to distutils. There's one thing though that I fail to understand, and I didn't see it addressed in any tutorial I've read about this: What if setuptools isn't installed? I understand it's not ...

Public API with Private Elements in Python

I'm working on a web mapping service and would like to provide my users with a Python API that they can use to create custom plugins. These plugins would be running on my server so I'm trying to lock down Python as much as possible. To ensure that users can't access files they are not supposed to, I'm planning on running the plugins ins...

Editing Windows registry, from Python, Under Linux

Hi All, I am looking for a Python API (or a C API as I am willing to bind) for editing Windows registries from XP to 7 from within a Linux system. The Windows target will be a mounted volume under Linux. I would be willing to code a library if none exists. Therefore, any docs or internals on the registry would be handy too. Any help,...

How to count the number of times something occurs inside a certain string?

In python, I remember there is a function to do this. .count? "The big brown fox is brown" brown = 2. ...

How to delete a certain IE cookie from python?

Hello, how can I delete IE 8 cookies for a certain site from Python? TIA ...

file size is dramatically increased after pickle

I'm reading in a file and sending the data (once encrypted) to a dictionary, with a hash of the data before and after encryption. I then pickle the dictionary but find the file size is massive compared to the source file size. If I write the encrypted data straight to a file the size is identical to the source. Any idea why my pickled fi...

Mount a filesystem using python

I'm sure this is a easy question, my Google-fu is obviously failing me. How do you mount a filesystem using Python (i.e the equivalent of running the shell command mount ...). Obviously you can use os.system to run the shell command, but surely this is a nice tidy, python interface to the mount system call. I can't find it (I thought i...

Python: Removing characters from beginnings of sequences in fasta format

Hi, I have sequences in fasta format that contains primers of 17 bp at the beginning of the sequences. And the primers sometimes have mismatches. I therefore want to remove the first 17 chars of the sequences, except from the fasta header. The sequences look like this: > name_name_number_etc SEQUENCEFOLLOWSHERE > name_number_etc SEQUE...

Accessing POST params with same name in python

I need to get values of these check boxes with same name through HTTP "POST". <input type="checkbox" id="dde" name="dept[]" value="dde"/> <input type="checkbox" id="dre" name="dept[]" value="dre"/> <input type="checkbox" id="iid" name="dept[]" value="iid"/> How to get these values in python using self.request.get() method? ...

Visibility_notify event in pyGTK

Hello, I am on windows and I am developing a pygtk app. I need to know when a window is visible or hidden by another window. In order to stop an heavy drawing process. http://www.pygtk.org/docs/pygtk/class-gtkwidget.html#signal-gtkwidget--visibility-notify-event I Use the visibility_notify_event to be notified on windows visibility st...

Best way to convert HTML to plaintext using Python

I'm working on a project that involves converting a large amount of HTML content to plain/text. I have a custom-written module that does the job OK, but I'm wondering if there's some standard tools to help get the job done. ...

How to de-import a Python module?

I am in the process of coding an app which has to get the metadata (author,version..etc) out of several modules (.py files) and display them. The user selects a script and the script is executed. (New scripts can be added and old ones be taken of from the target folder just like a plugin system). Firstly I import a script and I take o...

Summing Consecutive Ranges Pythonically

I have a sumranges() function, which sums all the ranges of consecutive numbers found in a tuple of tuples. To illustrate: def sumranges(nums): return sum([sum([1 for j in range(len(nums[i])) if nums[i][j] == 0 or nums[i][j - 1] + 1 != nums[i][j]]) for i in range(len(nums))])...

Where does Python first look for files?

I'm trying to learn how to parse .txt files in Python. This has led me to opening the interpreter (terminal > python) and playing around. However, I can't seem to be able to specify the right path. Where does Python first look? This is my first step: f = open("/Desktop/temp/myfile.txt","file1") This blatantly doesn't work. Can an...

order_with_respect_to() Child relationship

I'm trying to figure out how I can use: order_with_respect_to() to order via a Child relationship class Product(models.Model): name = models.CharField(max_length=100) class Affiliate(models.Model): product = models.ForeignKey(Product) clicks = models.IntegerField(default=0) I want to be able to display the Products in or...

Extending forms.SelectMultiple Without Losing Values

I have a model form that I am writing a custom widget for in order to replace the many-to-many forms.SelectMultiple fields with jQuery FCBKcomplete widgets. While the replacement of the multiselect element works fine, it is no longer pulling the options for the multiselect. Here is my widget: class FCBKcompleteWidget(forms.SelectMultip...

Python: importing through function to main namespace

(Important: See update below.) I'm trying to write a function, import_something, that will important certain modules. (It doesn't matter which for this question.) The thing is, I would like those modules to be imported at the level from which the function is called. For example: import_something() # Let's say this imports my_module my_...

Filtering by dates in Google App Engine's Datastore

I'm having some issues trying to filter a set of objets by their date. Right now I can get all of a user's transactions like this: > t = Transaction.all().filter("client_email =", "some_email").filter("application_id =", "foo").fetch(100) > len(t) # => 4 Now, if I want to set up some date filters: > min = datetime.datetime(2009, 2, 3...

Reading bytestreams in Python

I'm using Python appscript to write artwork to my iTunes Songs. I have a file stored in .pict format and when i use the normal open and read() routines, it reads the content as a string (encoded in utf-8). imFile = open('/Users/kartikaiyer/temp.pict','r') data = imFile.read() it = app('iTunes') sel = it.current_track.get() sel.artworks...