Re: string: __iter__()?

2006-10-04 Thread mrquantum
John Roth: > The iter() builtin creates an iterator for any > object that obeys the sequence protocol. > Since strings obey the sequence protocol there > is no real advantage to adding yet another > protocol to an already very fat object. Okay! > This does, however, mean that testing > for the

string: __iter__()?

2006-10-04 Thread mrquantum
Hello! Just for curiosity i'd like to know why strings don't support the iteration protocoll!? Is there some deeper reason for this? >>> hasattr('SomeString', '__iter__') False In Python 2.5 it's actually simple to obtain one: >>> myIter = (c for c in 'SomeString') >>> myIter.next() 'S' Thanks

Re: string: __iter__()?

2006-10-04 Thread mrquantum
Am Wed, 04 Oct 2006 12:03:41 +0200 schrieb Fredrik Lundh: > > really? iter("SomeString") works just fine for me. > Hmm, right! But then why doesn't dir('SomeString') show an __iter__ method? Seems to be implmented differently than with e.g. lists? Know why? -- http://mail.python.org/mailman/

Re: string: __iter__()?

2006-10-04 Thread mrquantum
Am Wed, 04 Oct 2006 11:59:07 +0200 schrieb mrquantum: > Hello! > > Just for curiosity i'd like to know why strings don't support the > iteration protocoll!? Is there some deeper reason for this? > Sorry, was to hasty by saying "... don't support the iterat

Re: string: __iter__()?

2006-10-04 Thread mrquantum
Am Wed, 04 Oct 2006 12:24:48 +0200 schrieb Peter Otten: > > The older pre-__iter__() iteration style relying on __getitem__() still > works: > class A: > ... def __getitem__(self, index): > ... return [3,2,1][index] > ... for item in A(): > ... print item > ... > 3