python

Slice a 2D Python Array

I have a 2d array in the numpy module that looks like: data = array([[1,2,3], [4,5,6], [7,8,9]]) I want to get a slice of this array that only includes certain columns of element. For example I may want columns 0 and 2: data = [[1,3], [4,6], [7,9]] What is the most Pythonic way to do thi...

Parsing 'time string' with Python?

I'm writing an application that involves having users enter time's in the following format: 1m30s # 1 Minute, 30 Seconds 3m15s # 3 Minutes, 15 Seconds 2m25s # 2 Minutes, 25 Seconds 2m # 2 Minutes 55s # 55 Seconds The data can have a single "minute designation", a single "second designation", or both. What is the proper way ...

The Tkinter Entry widget

Is there any way to make the widget so that text can be highlighted and copied, but not changed? ...

Reading Text with Accent - Python

I did some script in python that connects to GMAIL and print a email text... But, often my emails has words with "accent". And there is my problem... For example a text that I got: "PLANO DE S=C3=9ADE" should be printed as "PLANO DE SAÚDE". How can I turn legible my email text? What can I use to convert theses letters with accent? Tha...

clean method to get an entry in a list and set it as the first entry

so I list mList = ['list1', 'list2', 'list8', 'list99'] I want to choose a value in that list say 'list8' and have it so that it is the first entry in the list ['list2', 'list1', 'list8', 'list99'] how do I reorder just this one entry all I can think of at the moment is -get the index -remove that entry -insert(0, entry) what is a cl...

Python - How to recursively add a folder's content in a dict

I am building a python script which will be removing duplicates from my library as an exercise in python. The idea is to build a dict containing a dict ( with the data and statistic on the file / folder ) for every file in folder in the library. It currently works with a set number of subfolder. This is an example of what it gives out...

programmatically executing and terminating a long-running batch process in python

Hi guys, I have been searching for a way to start and terminate a long-running "batch jobs" in python. Right now I'm using "os.system()" to launch a long-running batch job inside each child process. As you might have guessed, "os.system()" spawns a new process inside that child process (grandchild process?), so I cannot kill the batch ...

Can't get Celery run_every property to work

I'm trying to create some Celery Periodic Tasks, and a few of them need to have the ability to change the run_every time at runtime. The Celery documentation says I should be able to do this by turning the run_every attribute into a property (http://packages.python.org/celery/faq.html#can-i-change-the-interval-of-a-periodic-task-at-runt...

Using pexpect to listen on a port from a virtualbox

Hi all, I am trying to create a tcplistener in python (using pexpect if necessary) to listen for tcp connection from Ubuntu in virtualbox on a windows xp host. I would really appreciate it, if one of you could point me in the right direction. Thank you. P.S: I have limited experience in the area, any help would be welcome. ...

Python - How to update a multi-dimensional dict

Follow up of my previous question: http://stackoverflow.com/questions/3680464/python-how-to-recursively-add-a-folders-content-in-a-dict. When I build the information dict for each file and folder, I need to merge it to the main tree dict. The only way I have found so far is the write the dict as a text string and have it interpreted in...

(Spring MVC)-like framework in python

Do you know a framework in Python which is similar to the Spring MVC java framework? What I'd love to have is that magic Converters that get, say, a movie_id from the request url and automatically fetch the Movie from you database and call a method of yours passing the object. If you have used Spring MVC you might understand what I mea...

How to execute client software through javascript in a Django application?

Im thinking about creating an asset management application in Django. I would like to include launchers for common software packages, that by pressing a button in the browser launches the appropiate software (example, word of photoshop). How would I go on about doing this? ...

pywin32 CreateEvent and Apache

Hello all, I have a website in Django1.1.1 deployed in Apache2.0. In the backend I have a launcher script that starts three python processes that interact with the frontend. One of these processes uses a Windows Event (using CreateEvent) that communicates with Apache. My problem is that when I run the launcher script first and then sta...

Compensate for Auto White Balance with OpenCV

I'm working on an app that takes in webcam data, applies various transformations, blurs and then does a background subtraction and threshold filter. It's a type of optical touch screen retrofitting system (the design is so different that tbeta/touchlib can't be used). The camera's white balance is screwing up the threshold filter by bri...

python class [] function

I recently moved from ruby to python and in ruby you could create self[nth] methods how would i do this in python? in other words you could do this a = myclass.new n = 0 a[n] = 'foo' p a[n] >> 'foo' ...

Rebind button with wxpython

I have this button : self.mybutton= wx.Button(self, -1, label= "mylabel", pos=(100,180)) self.Bind(wx.EVT_BUTTON, self.Onbutton, self.mybutton) and need to Bind it to another function whenspecifc radio button is choosen for exmaple : def onRadiobutton(self,event) : if choosen radio button : bind the mybutton to another func...

Update a record in a table in SQLAlchemy and Python

I have some problems when I try to update information in some tables. For example, I have this table: class Channel(rdb.Model): rdb.metadata(metadata) rdb.tablename("channels") id = Column("id", Integer, primary_key=True) title = Column("title", String(100)) hash = Column("hash", String(50)) runtime = Column("ru...

django-admin.py startproject is not working

after installing django I tried django-admin.py startproject mysite and that worked, then I got a simple site working and I wanted to start on something real, so I tried django-admin.py startproject newsite and nothing happened. Whenever I try the command nothing happens now.. any idea what is wrong? ...

Can I get a reference to a Python property?

If I have this: class foo(object): @property def bar(self): return 0 f = foo() How do I get a reference to f.bar without actually invoking the method, if this is even possible? Edited to add: What I want to do is write a function that iterates over the members of f and does something with them (what is not important)...

Problem reading URL with Python. Code opens up any other URL. Possible Header or Cookie problem.

Using python urllib or urllib2, for the life of me, I can not read the following URL: http://celem.michoacan.gob.mx/celem/publica/ficha_informativa_ordenamiento.jsp?p_id_ordenamiento=478 This page reads fine with Firefox or IE. I tried spoofing the User-Agent to simulate Firefox to no avail. This site uses cookies. I also tried using th...