python

Pattern matching of lists in Python

I want to do some pattern matching on lists in Python. For example, in Haskell, I can do something like the following: fun (head : rest) = ... So when I pass in a list, head will be the first element, and rest will be the trailing elements. Likewise, in Python, I can automatically unpack tuples: (var1, var2) = func_that_returns_a_tu...

Is there a windows implementation to python libsvn?

Because windows is case-insensitive and because SVN is case-sensitive and because VS2005 tends to rename files giving them the lower-case form which messes my repositories' history, I've tried to add the pre-commit hook script from http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/case-insensitive.py. Sure enough, the script use...

Match unicode in ply's regexes

I'm matching identifiers, but now I have a problem: my identifiers are allowed to contain unicode characters. Therefore the old way to do things is not enough: t_IDENTIFIER = r"[A-Za-z](\\.|[A-Za-z_0-9])*" In my markup language parser I match unicode characters by allowing all the characters except those I explicitly use, because my m...

Is Python and pygame a good way to learn SDL?

If I want to move to C++ and SDL in the future, is Python and pygame a good way to learn SDL? ...

How can I support wildcards in user-defined search strings in Python?

Is there a simple way to support wildcards ("*") when searching strings - without using RegEx? Users are supposed to enter search terms using wildcards, but should not have to deal with the complexity of RegEx: "foo*" => str.startswith("foo") "*foo" => str.endswith("foo") "*foo*" => "foo" in str (it gets more complicated when...

XPath search with ElementTree

New to xml. Looking for XPath to search a xml file with python ElementTree format <root> <child>One</child> <child>Two</child> <child>Three</child> </root> to do search for child with "Two" and return true/false if it was started off like from elementtree import ElementTree root = ElementTree.parse(open(PathFile)).getroot() how ...

How do I install plpython on MacOs X 10.5?

I have just installed PostgreSQL 8.3.4 on Mac OS X 10.5 (using ports), but I cannot figure out how to enable PL/Python. When I run the CREATE LANGUAGE plpythonu I get the following errors: ERROR: could not access file "$libdir/plpython": No such file or directory STATEMENT: CREATE LANGUAGE plpythonu; psql:<stdin>:18: ERROR: could not...

getting pywin32 to work inside open office 2.4 built in python 2.3 interpreter

I need to update data to a mssql 2005 database so I have decided to use adodbapi, which is supposed to come built into the standard installation of python 2.1.1 and greater. It needs pywin32 to work correctly and the open office python 2.3 installation does not have pywin32 built into it. It also seems like this built int python install...

How can I call a DLL from a scripting language?

I have a third-party product, a terminal emulator, which provides a DLL that can be linked to a C program to basically automate the driving of this product (send keystrokes, detect what's on the screen and so forth). I want to drive it from a scripting language (I'm comfortable with Python and slightly less so with Perl) so that we don'...

Python: DISTINCT on GQuery result set (GQL, GAE)

Imagine you got an entity in the Google App Engine datastore, storing links for anonymous users. You would like to perform the following SQL query, which is not supported: SELECT DISTINCT user_hash FROM links Instead you could use: user = db.GqlQuery("SELECT user_hash FROM links") How to use Python most efficiently to filter the r...

Python file interface for strings

Is there a Python class that wraps the file interface (read, write etc.) around a string? I mean something like the stringstream classes in C++. I was thinking of using it to redirect the output of print into a string, like this sys.stdout = string_wrapper() print "foo", "bar", "baz" s = sys.stdout.to_string() #now s == "foo bar baz" ...

WindowsError: priveledged instruction when saving a FreeImagePy Image in script, works in IDLE

I'm working on a program to do some image wrangling in Python for work. I'm using FreeImagePy because PIL doesn't support multi-page TIFFs. Whenever I try to save a file with it from my program I get this error message (or something similar depending on which way I try to save): Error returned. TIFF FreeImage_Save: failed to open fil...

Unexpected feature in a Python list of lists

I needed to create a list of lists in Python, so I typed the following: myList = [[1] * 4] * 3 The list looked like this: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]] Then I changed one of the innermost values: myList[0][0] = 5 Now my list looks like this: [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]] which is not what...

Anyone using Python for embedded projects?

Hi All, My company is using Python for a relatively simple embedded project. Is anyone else out there using Python on embedded platforms? Overall it's working well for us, quick to develop apps, quick to debug. I like the overall "conciseness" of the language. The only real problem I have in day to day work is that the lack of stati...

Possible to integrate Google AppEngine and Google Code for continuous integration?

Anyone have any thoughts on how/if it is possible to integrate Google Code commits to cause a Google AppEngine deployment of the most recent code? I have a simple Google AppEngine project's source hosted on Google Code and would love if everytime I committed to Subversion, that AppEngine would reflect the latest commit. I don't mind if...

Python lazy list

I would like create my own collection that has all the attributes of python list and also knows how to saved/loaded itself database. Also I want to make the load implicit and lazy, as in it shouldn't get called at the point of creation of the list but at it's first usage. Is there a single __ xxx __ method I can override to load the li...

Single Table Inheritance in Django

Is there explicit support for Single Table Inheritance in Django? Last I heard, the feature was still under development and debate. Are there libraries/hacks I can use in the meantime to capture the basic behavior? I have a hierarchy that mixes different objects. The canonical example of a corporation structure with an Employee class, ...

Python snippet to remove C and C++ comments

I'm looking for Python code that removes C and C++ comments from a string. (Assume the string contains an entire C source file.) I realize that I could .match() substrings with a Regex, but that doesn't solve nesting /*, or having a // inside a /* */. Ideally, I would prefer a non-naive implementation that properly handles awkward case...

Reading collections of extended elements in an RSS feed with Universal Feed Parser

Is there any way to read a collection of extension elements with Universal Feed Parser? This is just a short snippet from Kuler RSS feed: <channel> <item> <!-- snip: regular RSS elements --> <kuler:themeItem> <kuler:themeID>123456</kuler:themeID> <!-- snip --> <kuler:themeSwatches> <kuler:swatch> ...

I want a program that writes every possible combination to a different line of a text file.

OK, so basically what I want is a program that would print every combination of a set of variables to a different line of a text file, creating a word list. for example, print all binary number combinations possible up to for 1, 2, and 3 digits: 0 1 00 01 10 11 000 001 010 011 100 101 110 111 But putting each one of those answers on...