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...
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...
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...
If I want to move to C++ and SDL in the future, is Python and pygame a good way to learn SDL?
...
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...
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 ...
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...
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...
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'...
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...
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"
...
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...
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...
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...
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...
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...
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, ...
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...
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>
...
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...