Re: unexpect behavior from my added method

Guido van Rossum (Guido.van.Rossum@cwi.nl)
Sat, 01 Aug 1992 01:54:14 +0200

Terence Brannon writes:

>def gettext(self):
> self.editor.gettext()

and wonders why it doesn't work (it prints the value but returns
None).

Try this instead:

def gettext(self):
return self.editor.gettext()

This probably belongs in the FAQ: any expression that doesn't evaluate
to "None" is printed when executed as a statement. This is useful
when using Python as an interactive calculator. I left it in for
non-interactive statements: partly to simplify the interpreter (it's
not always easy to figure out whether a statement is executed
interactively; partly for consistency (a statement's effect is the
same interactively or in a function); partly to force programmers to
think about what to do with function return values. If you don't want
to use a value returned by a function you have to assign it to a dummy
variable. If you want to return it, you must use a return statement.

--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
"I don't care how excrementally runny it is, hand it over with all speed!"