IsPython really O-O?

gbreed at gbreed at
Thu Nov 15 18:44:35 CET 2001

Ken Seehof wrote:

> ... in fact
> here's a recipe describing how to add or replace a method in an existing
> class
> using the 'new' module:

AIUI, that involves a circular reference.  If anybody wants to try some 
benchmarking, compare it with the following:

dynamicModule = "__dynamic__"

def setDynamicClass(object):
  if object.__class__.__module__ != dynamicModule:
    class klass(object.__class__):
      """dynamic class for hacking"""
    klass.__name__ = object.__class__.__name__
    klass.__module__ = dynamicModule
    object.__class__ = klass

def addMethod(object, function):
  setattr(object.__class__, function.__name__, function)


More information about the Python-list mailing list