my code run wrong
class a(object):
def __iter(self):
return 33
b={'a':'aaa','b':'bbb'}
c=a()
print b.itervalues()
print c.itervalues()
Please try to use the code, rather than text, because my English is not very good, thank you
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
a. Spell it right: not
but:
with
__before and afteriter.b. Make the body right: not
but:
or
return iter([33])
If you
returna value from__iter__, return an iterator (an iterable, as inreturn [33], is almost as good but not quite…); or else,yield1+ values, making__iter__into a generator function (so it intrinsically returns a generator iterator).c. Call it right: not
but, e.g.:
or
itervaluesis a method of dict, and has nothing to do with__iter__.If you fix all three (!) mistakes, the code works better;-).