python

How to extract frequency information from an input audio stream (using PortAudio)?

I want to record sound (voice) using PortAudio (PyAudio) and output the corresponding sound wave on the screen. Hopeless as I am, I am unable to extract the frequency information from the audio stream so that I can draw it in Hz/time form. Here's an example code snippet that records and plays recorded audio for five seconds, in case i...

Credit card payments and notifications on the Google App Engine

I ported gchecky to the google app engine. you can try it here It implements both level 1 (cart submission) and level 2 (notifications from google checkout). Is there any other payment option that works on the google app engine (paypal for example) and supports level 2 (notifications)? ...

Is it safe to make an old-style class into a new-style class using Multiple Inheritance?

In a program that I'm writing, I wanted to make a ConfigParser that's read only so that it can safely be used globally. I didn't realize this, but apparently the SafeConfigParser is an old-style class, thus I had to subclass it like this: class ConstParser(SafeConfigParser, object): """This is a implementation of the SafeConfigPar...

Splitting a person's name into forename and surname

ok so basically I am asking the question of their name I want this to be one input rather than Forename and Surname. Now is there any way of splitting this name? and taking just the last word from the "Sentence" e.g. name = "Thomas Winter" print name.split() and what would be output is just "Winter" ...

Does Python 2.5 include a package to natively transform an XML document?

In my Python app, I have an XML document that I'd like to transform using my XSL file. I'm currently using xml.etree to generate the XML document, but I haven't found anything within Python 2.5 that will allow me to natively transform my XML document. I've already found one library (libxslt) which can execute the transformation, but I ...

Hashtable/dictionary/map lookup with regular expressions

I'm trying to figure out if there's a reasonably efficient way to perform a lookup in a dictionary (or a hash, or a map, or whatever your favorite language calls it) where the keys are regular expressions and strings are looked up against the set of keys. For example (in Python syntax): >>> regex_dict = { re.compile(r'foo.') : 12, re.c...

What's the best way to generate a UML diagram from Python source code?

A colleague is looking to generate UML class diagrams from heaps of Python source code. He's primarily interested in the inheritance relationships, and mildly interested in compositional relationships, and doesn't care much about class attributes that are just Python primitives. The source code is pretty straightforward and not tremend...

Most efficient way to search the last x lines of a file in python

I have a file and I don't know how big it's going to be (it could be quite large, but the size will vary greatly). I want to search the last 10 lines or so to see if any of them match a string. I need to do this as quickly and efficiently as possible and was wondering if there's anything better than: s = "foo" last_bit = fileObj.readl...

Play audio with python

How can i play audio (it would be like a 1sec sound) from a python script? It would be best if it was platform independent, but first of it needs to work on a mac. I know i could just execute the 'afplay file.mp3' command from within python, but is it possible to do it in raw python? I would also be better if it diddnt rely on external...

How to build Python C extension modules with autotools

Most of the documentation available for building Python extension modules uses distutils, but I would like to achieve this by using the appropriate python autoconf & automake macros instead. I'd like to know if there is an open source project out there that does exactly this. Most of the ones I've found end up relying on a setup.py file...

How do I protect python code?

I am developing a piece of software in python that will be distributed to my employer's customers. My employer wants to limit the usage of the software with a time restricted license file. If we distribute the .py files or even .pyc files it will be easy to (decompile), and remove the code that checks the license file. Another aspect i...

Converting a List of Tuples into a Dict in Python

Hi, I have a list of tuples like this: [ ('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('c', 1), ] I want to iterate through this keying by the first item, so for example I could print something like this: a 1 2 3 b 1 2 c 1 How would I go about doing this without keeping an item to track whether the first item is the same as I...

How do I safely decode a degrees symbol in a wxPython app?

I have a debug app I've been writing which receives data from a C-based process via UDP. One of the strings sent to me contains a '°' character - http://en.wikipedia.org/wiki/Degree_symbol">Unicode U+00B0 (which incidentally breaks the StackOverflow search function!). When my wxPython application tries to append that string to a text box...

making a programme run indefinitely in python

Is there any way to make a function (the ones I'm thinking of are in the style of the simple ones I've made which generate the fibonnacci sequence from 0 to a point, and all the primes between two points) run indefinitely. E.g. until I press a certain key or until a time has passed, rather than until a number reaches a certain point? ...

Is it possible to change the Environment of a parent process in python?

In Linux When I invoke python from the shell it replicates its environment, and starts the python process. Therefore if I do something like the following: import os os.environ["FOO"] = "A_Value" When the python process returns, FOO, assuming it was undefined originally, will still be undefined. Is there a way for the python process (o...

Creating a python win32 service

I am currently trying to create a win32 service using pywin32. My main point of reference has been this tutorial: http://code.activestate.com/recipes/551780/ What i don't understand is the initialization process, since the Daemon is never initialized directly by Daemon(), instead from my understanding its initialized by the following: ...

Merging/adding lists in Python

I'm pretty sure there should be a more Pythonic way of doing this - but I can't think of one: How can I merge a two-dimensional list into a one-dimensional list? Sort of like zip/map but with more than two iterators. Example - I have the following list: array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] I want to have result = [12, 15, 18] #...

We have a graphical designer, now they want a text based designer. Suggestions?

I'm sorry I could not think of a better title. The problem is the following: For our customer we have created (as part of a larger application) a graphical designer which they can use to build "scenario's". These scenario's consist of "Composites" which in turn consist of "Commands". These command objects all derive from CommandBase a...

What is a Ruby equivalent for Python's "zip" builtin?

Is there any Ruby equivalent for Python's builtin zip function? If not, what is a concise way of doing the same thing? A bit of context: this came up when I was trying to find a clean way of doing a check involving two arrays. If I had zip, I could have written something like: zip(a, b).all? {|pair| pair[0] === pair[1]} I'd also acce...

launching VS2008 build from python

if I paste this into the command prompt by hand, it works, but if I run it from python, I get The filename, directgory name, or volume label syntax is incorrect. os.system('%comspec% /k ""C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86') os.system('devenv Immersica.sln /rebuild Debug /Out last-build.txt') ...