Runtime check of methods

meow meowing at banet.net
Mon Aug 23 19:34:02 CEST 1999


Per Kistler <kistler at 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




More information about the Python-list mailing list