Re: except KeyError, everywhere --> memoization

2011-06-04 Thread Wilbert Berendsen
Hi, Many thanks for everyone's explanations and pointers! thanks! Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi -- http://mail.python.org/mailman/listinfo/python-list

except KeyError, everywhere

2011-06-03 Thread Wilbert Berendsen
self.func = func def __missing__(self, key): res = self[key] = self.func(key) return res Are there other peoply using things like this? Is there a solution like this in the standard lib that I'm overlooking? Of course 'except KeyError' everywhere is not re

Re: bdist_wininst: install_script not run on uninstall

2011-05-28 Thread Wilbert Berendsen
not this weekend...) Great that you found the cause of the bug! I looked for hours in the install.c but I didn't find it :-) Looking forward to a fix, which will make bdist_wininst much more usable! thanks! Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the ch

bdist_wininst: install_script not run on uninstall

2011-05-25 Thread Wilbert Berendsen
all script is not run? with best regards, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi -- http://mail.python.org/mailman/listinfo/python-list

SOLVED Re: distutils on windows ignoring package_data

2011-05-21 Thread Wilbert Berendsen
Solved: the problem was right there in the packagelist() function, it replaced '/' with dots instead of using os.sep ... I'm very sorry for the noise, although it's surprising everything else works without dots in the packages names :-) with regard, Wilbert

distutils on windows ignoring package_data

2011-05-21 Thread Wilbert Berendsen
package_dir incantation, but it doesn't help on Windows and on Linux it worked perfectly without. Does anybody have a clue why Python distutils on Windows ignore the package_data? (Note: sdist perfectly works as the data files are also listed in MANIFEST.in) tia, Wilbert Berendsen --

counting character occurrences

2010-01-23 Thread Wilbert Berendsen
with codecs.open(filename, 'r', 'utf-8') as f: counted = Counter(f.read()) for c, n in counted: print(c, n, sep='\t') with best regards, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ -- http://mail.python.org/mailman/listinfo/python-list

Re: counting lines of code

2010-01-22 Thread Wilbert Berendsen
Op donderdag 21 januari 2010 schreef Michele: > I need a small utility to count the lines of Python code in a > directory, traversing subdirectories and ignoring comments and > docstrings. sloccount can do this. http://www.dwheeler.com/sloccount/ Met vriendelijke groet, Wilbert

Re: substitution

2010-01-21 Thread Wilbert Berendsen
ns a translator given a mapping. The translator can be called to perform replacements in a string: import re def translator(mapping): keys = sorted(mapping.keys(), key=len, reverse=True) rx = re.compile("|".join(keys)) repl = lambda m: mapping[m.group()] re

Re: substitution

2010-01-21 Thread Wilbert Berendsen
rx = re.compile("|".join(keys)) repl = lambda x: mapping[x.group()] s = "fooxxxbazyyyquuux" rx.sub(repl, s) One thing remaining: if the replacement keys could contain non-alphanumeric characters, they should be escaped using re.escape: rx = re.compile("|".join

Re: Idioms and Anti-Idioms Question

2009-06-22 Thread Wilbert Berendsen
bar()['first'][0] * baz.quux(1, 2)[5:9] + calculate_number(10, 20) * forbulate(500, 360)) w best regards, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi -- http://mail.python.org/mailman/listinfo/python-list

Re: Determining when a file has finished copying

2008-07-19 Thread Wilbert Berendsen
You could also copy to a different name on the same disk, and when the copying has been finished just 'move' (mv) the file to the filename the other application expects. E.g. QMail works this way, writing incoming mails in folders. Met vriendelijke groet, Wilbert Berendsen

manipulating class attributes from a decorator while the class is being defined

2008-04-19 Thread Wilbert Berendsen
n a decorator? Thanks for any help, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi -- http://mail.python.org/mailman/listinfo/python-list

Re: pty.spawn directs stderr to stdout

2008-04-12 Thread Wilbert Berendsen
Op zaterdag 12 april 2008, schreef Wilbert Berendsen: > I'm currently trying to combine subprocess.Popen with pty.openpty ... which succeeded :-) http://code.google.com/p/lilykde/source/browse/trunk/runpty.py?r=314 it seems to work :-) thanks, Wilbert Berendsen -- http://www.wilbertbere

Re: pty.spawn directs stderr to stdout

2008-04-12 Thread Wilbert Berendsen
e then STDERR is not dup'ed to the pty. I'm currently trying to combine subprocess.Popen with pty.openpty ... tx, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi -- http://mail.python.org/mailman/listinfo/python-list

pty.spawn directs stderr to stdout

2008-04-10 Thread Wilbert Berendsen
Hi, using pty.spawn() it seems that stderr output of the spawned process is directed to stdout. Is there a way to keep stderr separate and only direct stdin and stdout to the pty? TIA, w best regards, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wi

And the reverse? Does os also import os.path?

2008-03-27 Thread Wilbert Berendsen
If i do >>> import os >>> os.path.abspath("bla") '/home/wilbert/bla' >>> it seems that just import os also makes available al os.path functions. But is that always true? Thanks, Wilbert -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatm

Thanks. (Re: keeping state in an iterator object by rebinding next())

2008-03-20 Thread Wilbert Berendsen
Thanks for all the elaborate answers and help! It helped me deepening my understanding of Python. Sincere, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandhi -- http://mail.python.org/mailman/listi

keeping state in an iterator object by rebinding next()

2008-03-19 Thread Wilbert Berendsen
ing to the correct method from within the next() method. But that gives an extra call... Met vriendelijke groet, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in the world." -- Mahatma Gandi -- http://mail.python.org/mailman/listinfo/python-list

building arbitrary files with distutils?

2008-03-10 Thread Wilbert Berendsen
build' ? I can write python functions to perform those command, and I found timestamp checking functions in distutils.dep_util, but just can't find the way to connect such commands to the build step w best regards, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You mu

pure python hyphenator

2008-03-09 Thread Wilbert Berendsen
enator . It needs more testing but seems to work nice. LilyKDE is located at http://lilykde.googlecode.com/ all the best. Guido and community: thanks for such a nice programming language, Wilbert Berendsen -- http://www.wilbertberendsen.nl/ "You must be the change you wish to see in t