Re: How to do this in Python? - A "gotcha"

2009-03-18 Thread S Arrowsmith
Jim Garrison wrote: >It's a shame the iter(o,sentinel) builtin does the >comparison itself, instead of being defined as iter(callable,callable) >where the second argument implements the termination test and returns a >boolean. This would seem to add much more generality... is >it worthy of a PEP

Re: Creating 50K text files in python

2009-03-18 Thread S Arrowsmith
venutaurus...@gmail.com wrote: >FName = "TextFile"+c+"_"+d+"_"+p+".txt" >l = 1 >for l in range(1 , 11): >os.system ("\"echo "+FName+" >> "+FName+"\"") >l = l +1 1. os.system spawns a new process, which on Windows (I'm guessing you're on Windows give

Re: String to sequence

2009-03-16 Thread S Arrowsmith
Peter Otten <__pete...@web.de> wrote: >assert s.startswith("[") >assert s.endswith("]") >s = s[1:-1] s.strip('[]') (I suppose it all depends on how much you can trust the consistency of the input.) -- \S under construction -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is lambda allowed as a key in a dict?

2009-03-10 Thread S Arrowsmith
Iain King wrote: >Sort of tangenitally; is there any real difference between the outcome >of the two following pieces of code? > >a = lambda x: x+2 > >def a(x): >return x+2 a.__name__ As for why that matters, try a(None) and see which gives the more informative traceback. -- \S under

Re: speeding up reading files (possibly with cython)

2009-03-09 Thread S Arrowsmith
Carl Banks wrote: >When building a very large structure like you're doing, the cyclic >garbage collector can be a bottleneck. Try disabling the cyclic >garbage collector before building the large dictionary, and re- >enabling it afterwards. > >import gc >gc.disable() >try: >for line in file:

Re: String Identity Test

2009-03-04 Thread S Arrowsmith
Avetis KAZARIAN wrote: >It seems that any strict ASCII alpha-numeric string is instantiated as >an unique object, like a "singleton" ( a =3D "x" and b =3D "x" =3D> a is b = >) >and that any non strict ASCII alpha-numeric string is instantiated as >a new object every time with a new id. What no-o

Re: count secton of data in list

2009-02-23 Thread S Arrowsmith
In article <3ed253bb-d6ec-4f47-af08-ad193e9c4...@h16g2000yqj.googlegroups.com>, odeits wrote: >def count_consecutive(rows): >switch =3D 0 >count =3D 0 >for r in rows: >if r[-1] =3D=3D switch: >count +=3D 1 >else: >switch =3D not switch >