Why require __init__ to return None?

Steven Miale (smiale@cs.indiana.edu)
Fri, 27 May 1994 09:46:03 -0500

I am trying to write a generator that is initialized with a list
and then returns each element sequentially.

The easiest way to do this seemed to be to write a class, like so:

class Iterator:
def __init__(self, list):
return self.generator
def generator(self):
self.pos = self.pos + 1
return self.list[self.pos]

Thus, when the user called Iterator with a list:


This would then initialize the instance with the list, and return
an instance method (not the instance itself). This method (generator)
would then return 1, 2, etc.

>>> x = Iterator([1,2,3,4,5])
>>> x()
>>> x()

Unfortunately, Python requires that __init__ return None.

What I propose is that the user should be able to override the default
return value of __init__, by explicitly returning a value other than

I know that I can just write another function to return the generator,
but then my creation syntax becomes:

>>> x = Iterator().make([1,2,3,4,5])

which is not as pretty.

BTW: to add fuel to the syntax debate, I taught an "introduction to C"
lab last semester for the first time. I cannot tell you how many times
student's code wasn't doing what they wanted because they got the braces
wrong, like so:

if (x==3) {
do_this; }

Notice that the indentation was correct...


Steven Miale - smiale@cs.indiana.edu | Don't blame me - 
Indiana University, Bloomington, IN  | I voted Libertarian.