python

Renaming OS files

Hi all, I am trying to rename files based on their extensions. Below is my code, Somehow my os.rename isn't working. There aren't any errors though. I got no idea what is wrong. Hope you guys could help. Thanks. import os import glob directory = raw_input("directory? ") ext = raw_input("file extension? ") r = raw_input("replace name") p...

Handling file uploads in App Engine (python)

Hi, I am trying to implement a file upload solution using app engine and python. The thing which I am struggling with checking whether there is actually a file attached to the form or not. I am setting the enctype="multipart/form-data" and in principle it works. My python handler looks like this: fileupload = self.request.POST["content...

Inspecting urllib2.Request attributes when using OpenerDirector with handlers

Is it possible to inspect the attributes of an Python urllib2.Request (url, data, headers etc) when using an urllib2.OpenerDirector: cookie_jar = cookielib.CookieJar() opener = urllib2.OpenerDirector() opener.add_handler(urllib2.ProxyHandler()) opener.add_handler(urllib2.UnknownHandler()) opener.add_handler(urllib2.HTTPHandler()) op...

repeat y axis scale along grid line of graph ( matplotlib)

Hello, I am new to matplotlib and I am trying to figure out if I can repeat the y axis scale values along the grid lines of the line graph. The graph has 2 axis, x-axis has hourly values and y-axis has temperature values. I need to show the graph for 48 hours, so it results in a long horizontal graph. when user scrolls through the ...

django orm and 3 relations

Hi, I have a problem to transpose my sql request in the orm. Well, this my sql request : SELECT DISTINCT accommodation.id from accommodation LEFT JOIN product on product.accommodation_id=accommodation.id LEFT JOIN date on date.product_id = product.id WHERE date.begin> '2010-08-13'; So i want all the accommodations for a period, wit...

Python midi out to FruityLoops Studio

hi everybody, im working on a project and i want to create a virtual midi input with python to flstudio (fruityloops) i have googled a bit but all the modules i could find was about creating midi files which is not my issue. so what module should i use for midi i/o with python? ...

How do I dynamically add an attribute to a module from within that module?

Say in a module I want to define: a = 'a' b = 'b' ... z = 'z' For some set (in this case I chose letters). How do I dynamically set attributes on the current module? Something like: for letter in ['a', ..., 'z']: setattr(globals(), letter, letter) This doesn't work, but what would? (Also my understanding is that globals() wi...

Python ORM that automatically creates classes from DB schema

Hi, is there a python ORM (object relational mapper) that has a tool for automatically creating python classes (as code so I can expand them) from a given database schema? I'm frequently faced with small tasks involving different databases (like importing/exporting from various sources etc.) and I thought python together with the above...

How to insert only some specified characters in a tkinter Entry widget

I have a list of n Entry widgets. The user should be able to type only the following charaters: "V", "F", " ". If the user types one of those characters, the focus should pass from Entry #x to Entry #x+1, otherwise the focus should stay where it is (on Entry #x) and the input should be discarded. I am not able to discard the wrong input...

eric 5 ide for python

today i install eric 5 ide. whenever i run eric5.py i get an error msg poping a dialog box saying start debugger no python 2 interpreter configured... but i have a both python 2.6 and python 3.1 installed in the pc. i can't figured out the problem anymore please help me. ...

Help Creating Python Class with Tkinter

How do I create a class called rectangle that I can pass it the coordinates and a color and have it fill those one? from Tkinter import * master = Tk() w = Canvas(master, width=300, height=300) w.pack() class rectangle(): def make(self, ulx, uly, lrx, lry, color): self.create_rectangle(ulx, uly, lrx, lry, fill=color) re...

Uninstall pysvn in Mac OSX 10.5

I installed the wrong version of pysvn in my system using the .dmg. I realized the mistake and removed the pysvn folder from /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/. I don't see pysvn anywhere else on my system. Now when I try to install the correct (older) version of pysvn the installation process...

How do I dynamically create a function with the same signature as another function?

I'm busy creating a metaclass that replaces a stub function on a class with a new one with a proper implementation. The original function could use any signature. My problem is that I can't figure out how to create a new function with the same signature as the old one. How would I do this? Update This has nothing to do with the actual ...

Interestinting situation. DataBase Error? Python. Django.

In test server it is working. But production gives this traceback: what different? And what does that error mean? Different is only in python versions. In test server it is 2.6.5 and production 2.5.2. How can I get rid of this error with out changing version? True 2008-10-16 15:20:00 - did not match our database Traceback (most recen...

Accessing the same function from two different classes

Hi. I have two classes, suppose A and B. Within B, I instantiate A. I have a function func() that is required by both the classes. How should I go about it? I had thought of this approach: class A: func() class B: x = A() func() def func(): And then I can access func() from within A or B. Is this approach OK or is ther...

Python implementation of BLAST alignment algorithm?

Is anyone aware of a pure python implementation of BLAST alignment? I am trying to study this algorithm... ...

Change setuptools gcc buildpath for Python

I'm trying to install MySQLdb-python on a server I don't have root on. It doesn't have appropriate mysql development files that python setup.py build would usually compile into _mysql.so. I've obtained the files, and placed them in my home directory, however I can't get the build script to find them. When I run the build command, the sc...

Analyse data using time and date objects

I have a rather unique problem I'm trying to solve: Based on this sample data (actual data is very many records, and at least 4 per card per day): serial, card, rec_date, rec_time, retrieved_on 2976 00040 2010-07-29 18:57 2010-07-31 13:37:31 2977 00040 2010-07-30 09:58 2010-07-31 13:37:31 2978 00040 2010-07-30 15:33 2010-07-31 13:3...

Is it good style to call bash commands within a Python script using os.system("bash code")?

I was wondering whether or not it is considered a good style to call bash commands within a Python script using os.system(). I was also wondering whether or not it is safe to do so as well. I know how to implement some of the functionality I need in Bash and in Python, but it is much simpler and more intuitive to implement it in Bash. H...

Distribute points on a circle as evenly as possible

Hi SO community! Problem statement I have the following problem: I have a circle with a certain number (zero or more) of points on it. These positions are fixed. Now I have to position another set of points on the circle, such as all points together are as evenly distributed around the circle as possible. Goal My goal is now to devel...