S
Steven Brent
Hi folks,
In the snippet below, I'm trying to overload the __iter__ list method:
def __iter__(self):
print "using custom iter"
counter = 0
end = len(self.data) - 1
while counter <= end:
print self.data[counter]
counter += 1
It pretty much works, except that the output is ugly when the while loop
falls off the end of the list:
using custom iter
1
2
3
x
y
z
Traceback (most recent call last):
File "mylist.py", line 38, in ?
for item in L3rint item,
TypeError: iter() returned non-iterator of type 'NoneType'
Oh, yeah, plus it's adding a newline at the end of each item even though
I've got the comma there. I'm gonna keep plugging away to see if I can
figure this out, but stuff like this makes me frustrated... Thanks a
million.
In the snippet below, I'm trying to overload the __iter__ list method:
def __iter__(self):
print "using custom iter"
counter = 0
end = len(self.data) - 1
while counter <= end:
print self.data[counter]
counter += 1
It pretty much works, except that the output is ugly when the while loop
falls off the end of the list:
>>> L3 = [1,2,3,'x','y',z']
>>> for item in L3: print item,
using custom iter
1
2
3
x
y
z
Traceback (most recent call last):
File "mylist.py", line 38, in ?
for item in L3rint item,
TypeError: iter() returned non-iterator of type 'NoneType'
Oh, yeah, plus it's adding a newline at the end of each item even though
I've got the comma there. I'm gonna keep plugging away to see if I can
figure this out, but stuff like this makes me frustrated... Thanks a
million.