python

Converting from a string to boolean in Python?

Does anyone know how to do convert from a string to a boolean in Python? I found this link. But it doesn't look like a proper way to do it. I.e. using a built in functionality, etc. EDIT: The reason I asked this is because I learned int("string"), from here. I tried bool ("string") but always got True. ...

How can I talk to UniProt over HTTP in Python?

I'm trying to get some results from UniProt, which is a protein database (details are not important). I'm trying to use some script that translates from one kind of ID to another. I was able to do this manually on the browser, but could not do it in Python. In http://www.uniprot.org/faq/28 there are some sample scripts. I tried the Per...

Best way to encode tuples with json

In python I have a dictionary that maps tuples to a list of tuples. e.g. {(1,2): [(2,3),(1,7)]} I want to be able to encode this data use it with javascript, so I looked into json but it appears keys must be strings so my tuple does not work as a key. Is the best way to handle this is encode it as "1,2" and then parse it into somethi...

Launching a .py python script from within a cgi script

I'm trying to launch a .py script from within a cgi script while running a local cgi server. The cgi script simply receives some data from Google Earth and passes it to the .py script which is currently being called using execfile('script.py') placed at the end of the cgi script. The script runs to completion, however script.py contains...

Populating form field based on query/slug factor

I've seen some similar questions, but nothing that quite pointed me in the direction I was hoping for. I have a situation where I have a standard django form built off of a model. This form has a drop down box where you select an item you want to post a comment on. Now I'd like people to be able to browse by items, and click a link to co...

A wxPython timeline widget

Hello! I am looking for a certain wxPython widget to use in my program. I hope that something like this exists and that you might know where to find. I will try to describe the functionality I'm looking for: Imagine something like the widget that Audacity uses to display an audio track. It's a horizontal timeline, with a ruler. It is p...

OptionParser - supporting any option at the end of the command line

Hi guys, I'm writing a small program that's supposed to execute a command on a remote server (let's say a reasonably dumb wrapper around ssh [hostname] [command]). I want to execute it as such: ./floep [command] However, I need to pass certain command lines from time to time: ./floep -v [command] so I decided to use optparse.Option...

Why can't environmental variables set in python persist?

I was hoping to write a python script to create some appropriate environmental variables by running the script in whatever directory I'll be executing some simulation code, and I've read that I can't write a script to make these env vars persist in the mac os terminal. So two things: Is this true? and It seems like it would be a usefu...

Matrices in python

Yesterday I had the need for a matrix type in python. Apparently, a trivial answer to this need would be to use numpy.matrix(), but the additional issue I have is that I would like a matrix to store arbitrary values with mixed types, similarly to a list. numpy.matrix does not perform this. An example is >>> numpy.matrix([[1,2,3],[4,"5"...

My first python program: can you tell me what I'm doing wrong?

I hope this question is considered appropriate for stackoverflow. If not, I'll remove the question right away. I've just wrote my very first python program. The idea is that you can issue a command, and it's gets sent to several servers in parallel. This is just for personal educational purposes. The program works! I really want to get...

Why is my PyObjc Cocoa view class forgetting its fields?

I was trying to hack up a tool to visualize shaders for my game and I figured I would try using python and cocoa. I have ran into a brick wall of sorts though. Maybe its my somewhat poor understand of objective c but I can not seem to get this code for a view I was trying to write working: from objc import YES, NO, IBAction, IBOutlet fr...

join list of lists in python

Is the a short syntax for joining a list of lists into a single list( or iterator) in python? For example I have a list as follows and I want to iterate over a,b and c. x = [["a","b"], ["c"]] The best I can come up with is as follows. result = [] [ result.extend(el) for el in x] for el in result: print el ...

Packaging Ruby or Python applications for distribution?

Are there any good options other than the JVM for packaging Python or Ruby applications for distribution to end-users? Specifically, I'm looking for ways to be able to write and test a web-based application written in either Ruby or Python, complete with a back-end database, that I can then wrap up in a convenient set of platform-indepe...

Locating (file/line) the invocation of a constructor in python

I'm implementing a event system: Various pieces of code will post events to a central place where they will be distributed to all listeners. The main problem with this approach: When an exception happens during event processing, I can't tell anymore who posted the event. So my question is: Is there an efficient way to figure out who cal...

How do i enable sms notifications in my web app?

I have a web application which i want to enable real time sms notifications to users of the applications. I would like to know how to go about this. Note: i can not use twitter API because i live in west africa, and twitter doesnt send sms to my country Also email2sms is not an option because the movile operators dont allow that in my co...

Python's subprocess.Popen returns the same stdout even though it shouldn't

I'm having a very strange issue with Python's subprocess.Popen. I'm using it to call several times an external exe and keep the output in a list. Every time you call this external exe, it will return a different string. However, if I call it several times using Popen, it will always return the SAME string. =:-O It looks like Popen ...

Python: Queue.Queue vs. collections.deque

I need a queue which multiple threads can put stuff into, and multiple threads may read from. Python has at least two queue classes, Queue.Queue and collections.deque, with the former seemingly using the latter internally. Both claim to be thread-safe in the documentation. However, the Queue docs also state: collections.deque is an...

If monkey patching is permitted in both Ruby and Python, why is it more controversial in Ruby?

In many discussions I have heard about Ruby in which people have expressed their reservations about the language, the issue of monkey patching comes up as one of their primary concerns. However, I rarely hear the same arguments made in the context of Python although it is also permitted in the Python language. Why this distinction? ...

Parsing HTML in Python

What's my best bet for parsing HTML if I can't use BeautifulSoup or lxml? I've got some code that uses SGMLlib but it's a bit low-level and it's now deprecated. I would prefer if it could stomache a bit of malformed HTML although I'm pretty sure most of the input will be pretty clean. ...

Python and sockets +upnp

Hello, I have a question about python and sockets. As I understand, if you have router you must open a port before you can use it in your program. But if user can't do that... I heard something about UPnP. I don't know will it help with my problem, so I've asked you. Best regards. ...