python

Filter array to show rows with a specific value in a specific column

Let's say i have a multidimensional list l: l = [['a', 1],['b', 2],['c', 3],['a', 4]] and I want to return another list consisting only of the rows that has 'a' in their first list element: m = [['a', 1],['a', 4]] What's a good and efficient way of doing this? ...

Google App Engine won't recognize facebook package unless I rename it

I'm trying to intergrate Facebook Connect into an GAE app. I've got a basic folder structure like so: /gae-root /myapp /templates /etc app.yaml settings.py and I tried to add the PyFacebook library like so: /gae-root /myapp /templates /etc /facebook /djangofb app.yaml ...

How to use "class" the word as parameter function calls in python

I am writing an XML generator per my manager's request. For less typings' sake, I decided using ElementTree as parser and SimpleXMLWriter as writer. The result XML require attributes named "class". e.g. <Node class="oops"></Node> As the official tutorial suggested, to write an XML node just use this method: w.element("meta", name="...

how to drag image in a wxpython frame

hello what is the easiest way to drag an image ( or text) in a wx window ? i need steps or a small example on how to do that. thanx in advance ...

Why scipy.io.wavfile.read does not return a tuple?

I am trying to read a *.wav file using scipy. I do the following: import scipy x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav') As a result of this code I get: Traceback (most recent call last): File "test3.py", line 2, in <module> x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav') AttributeError...

ImportError: cannot import name NumpyTest

I am trying to read a *.wav file using scipy. I do it in the following way: import scipy.io x = scipy.io.wavfile.read('/usr/share/sounds/purple/receive.wav') As a result I get the following error message: Traceback (most recent call last): File "test3.py", line 1, in <module> import scipy.io File "/usr/lib/python2.5/site-pack...

Trying to open a serial port with pyserial on WinXP -> "Access denied"

I'm trying to send data to an hplc pump via the serial port using python and pyserial. I tested the cable and the pump under linux (a gentoo derivative), where it worked perfectly, albeit as root. Now i have to use the code on a WinXP machine, where i always get an "Access denied" error when trying to open the port (i adjusted the parame...

XML parsing with lxml and Python

Please help me to resolve my problem with lxml (I'm a newbie to lxml). How can I get "Comment 1" from the next file: <?xml version="1.0" encoding="windows-1251" standalone="yes" ?> <!--Comment 1--> <a> <!--Comment 2--> </a> ...

What is the easiest way to read wav-files using Python [summary]?

I want to use Python to access a wav-file and write its content in a form which allows me to analyze it (let's say arrays). I heard that "audiolab" is a suitable tool for that (it transforms numpy arrays into wav and vica versa). I have installed the "audiolab" but I had a problem with the version of numpy (I could not "from numpy.test...

Making Python Interactive Mode of Emacs Highlight and Indent

I am using Emacs 23 with python-mode 5.1.0 to edit my python programs. Sometimes when writing a program I want to run a small throwaway python script and so I run the interactive move (C-c !). This is fine, but it neither indents nor highlights the code, and if I try running python mode while in it, it no longer evaluates. So, how do I s...

Cambodian keyboard for Windows and Linux?

Before I created http://khmerlc.org/khmerkeyweb/ with javascript that allow user input cambodia unicode user can switch from English to khmer(cambodia) I am going to build an application called khmerkey for desktop (both can run window,linux). I will use python. the User interface it's very simple, just: With two options(allow user t...

Python elegant inverse function of int(string,base)

python allows conversions from string to integer using any base in the range [2,36] using: int(string,base) im looking for an elegant inverse function that takes an integer and a base and returns a string for example >>> str_base(224,15) 'ee' i have the following solution: def digit_to_char(digit): if digit < 10: return chr(o...

Find system folder locations in Python 3.1

I am trying to find out the location of system folders with Python 3.1. For example "My Documents" = "C:\Documents and Settings\User\My Documents", "Program Files" = "C:\Program Files" etc etc. ...

What is returned by wave.readframes?

I assign a value to a variable x in the following way: import wave w = wave.open('/usr/share/sounds/ekiga/voicemail.wav', 'r') x = w.readframes(1) When I type x I get: '\x1e\x00' So x got a value. But what is that? Is it hexadecimal? type(x) and type(x[0]) tell me that x and x[0] a strings. Can anybody tell me how should I interpre...

Qt Python: QTextEdit - display input

Hi Everybody, I have a QTextEdit... it works with 'clear()' when a pushbutton calls 'CleanComments' to clean the input done by the user. Here is the code: def CleanComments(self): self.textEditInput.clear() def showInput(self): print "show input: %s" % self.textEditInput.show() def buildEditInput(self): self.textEditInput...

Using SUDS to test WSDL

Does anyone know about a good SUDS tutorial. I am trying to run tests on WSDL files and I am having trouble finding any imformation on how to do this. Is SUDS much different to SOAPy and would anyone recommend it to run smoke tests on functions stored in WSDL files. I have read that SOAPAy is no longer supported in Python 2.6+. Is this ...

How should Django Apps bundle static media?

Hi all, Background: I'm starting to use Django for the first time, which is also my first foray into web development. I just got stuck on the whole "serving static media" problem. After spending a while looking at all the documentation and StackOverflow questions, I think I understand how it's supposed to work (i.e. MEDIA_ROOT, MEDIA_...

"Parseltongue": get Ruby to Speak a bit of Python ?

Just for interest really - community wiki - how much Python can we get Ruby to understand ? [ Probably be just as interesting to do the reverse as well]. The experiment (such as it is) perhaps to see how much can be written in Ruby-Cross-Python scripts that will result in identical outputs. The only 'cheat' I guess being allowed here is...

Remove lines from textfile with python

I have a textfile.txt like this: First Line Second Line Third Line Fourth Line Fifth Line Sixth Line How can I remove the first three lines and the last line most comfortable? Thanks! ...

private members in python

how can i make a methods and data members private in Python? Or doesn't python support private members?? ...