Runtime check of methods

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

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

=-=-=-= =-=-=-=
class Goofyclass:

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

=-=-=-= =-=-=-=
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.

More information about the Python-list mailing list