Re: Behavior of re.split on empty strings is unexpected

2010-08-05 Thread jhermann
On Aug 2, 7:34 pm, John Nagle wrote: >  >>> s2 = "   HELLO   THERE  " >  >>> kresplit4 = re.compile(r'\W+', re.UNICODE) >  >>> kresplit4.split(s2) > ['', 'HELLO', 'THERE', ''] > > I still get empty strings. >>> re.findall(r"\w+", " a b c ") ['a', 'b', 'c'] -- http://mail.python.org/mailman/list

Re: Your beloved python features

2010-02-11 Thread jhermann
$ python -c "import this" -- http://mail.python.org/mailman/listinfo/python-list

Re: Create object from variable indirect reference?

2009-11-17 Thread jhermann
On 10 Nov., 17:03, NickC wrote: > Many thanks for the replies.  getattr() works great: You can get a little more versatile and even specify the location of the name (i.e. the module / package name) without pre-importing it, like this... def importName(modulename, name=None): """ Import ident

Re: a splitting headache

2009-10-26 Thread jhermann
On 16 Okt., 02:18, Mensanator wrote: > All I wanted to do is split a binary number into two lists, > a list of blocks of consecutive ones and another list of > blocks of consecutive zeroes. Back to the OP's problem, the obvious (if you know the std lib) and easy solution is: >>> c = '0010100

Re: Q on explicitly calling file.close

2009-09-23 Thread jhermann
>     except: >         return 0 So wrong on so many levels... -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 crashes displaying Unicode at interactive prompt

2008-12-17 Thread jhermann
Assuming those survived the switch to 3.0, you can use site.py und sys.displayhook to customize to the old behaviour (i.e. change it to a version using ascii instead of repr). Since this only affects interactive use, it's also no problem for portability of code, unlike "solutions" like forcing the

Re: unittest exits

2008-11-19 Thread jhermann
On 13 Nov., 20:20, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > try: >     unittest.main() > except SystemExit: >     pass You most probably want this instead: try: unittest.main() except SystemExit, exc: # only exit if tests failed if exc.code: raise --

Re: Identifying unicode punctuation characters with Python regex

2008-11-19 Thread jhermann
> >>> P=P.replace('\\','').replace(']','\\]')   # escape both of them. re.escape() does this w/o any assumptions by your code about the regex implementation. -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem with sqlite3 cursor and imbricated for loop

2008-11-19 Thread jhermann
c.execute("select * from stocks") for s in list(c): print s[0] c.execute("select * from stocks where price<20") for sp in c: print ' '+sp[0] c.close() The simple addition of list() should do away with the dependency on mysql's implementation, since it forces the instant fetch of al

Re: Eggs, VirtualEnv, and Apt - best practices?

2008-10-01 Thread jhermann
Our solution consists of: * our own base python distribution, decoupled from the OS one (for various reasons, one being version independency) * distutils / setuptools / virtualenv is included in that python installation, no other eggs installed in site-packages * virtualenv + Paver to manage bui

Re: closures and dynamic binding

2008-10-01 Thread jhermann
I didn't see this mentioned in the thread yet: the double-lambda is unnecessary (and a hack). What you should do when you need early binding is... early binding. ;) Namely: f = [lambda n=n: n for n in range(10)] print f[0]() print f[1]() Note the "n=n", this prints 0 and 1 instead of 9/9. -- htt

Re: An idiom for code generation with exec

2008-06-25 Thread jhermann
Since nobody mentioned textwrap.dedent yet as an alternative to the old "if 1:" trick, I thought I should do so. :) -- http://mail.python.org/mailman/listinfo/python-list