Mailing List Archive

Runtime check of methods
Hi

Why does Python only runtime check, wether it knows
a method? For instance, if I forget to put the
"self." in front of a method in a class, than
python myclass.py still does not complain.

Thanks, Per.
--
Per Kistler kistler@fnmail.com / kistler@gmx.net
------------------------------------------------------------
Runtime check of methods [ In reply to ]
Per Kistler <kistler@fnmail.com> wrote:

> Why does Python only runtime check, wether it knows a method? For
> instance, if I forget to put the "self." in front of a method in a
> class, than python myclass.py still does not complain.

It's not necessarily an error. Remember that this language treats
everything as a big pile of function pointers and dispatch tables, and
you can mess around with them at run time. Try this:

=-=-=-= goofymod.py =-=-=-=
class Goofyclass:

def doit(self):
print unknownsub() # This doesn't look at all healthy.
#eof

=-=-=-= main.py =-=-=-=
import goofymod

def useful():
return "meow"

foo = goofymod.Goofyclass() # We still have no unknownsub,
goofymod.unknownsub = useful # but fix that here,
foo.doit() # and it even works.
#eof