News for hackers. Stuff that matters.
Re:Metaclasses in Python by reinhardt on Thursday December 15, 2011 @01:13PM (#3357221)
The above doesn't really work as the builtin object class doesn't allow extra attributes. Still any pure Python class does by default:

    class Foo(object):
        pass
    foo = Foo()
    foo.name = ...
    def hello(self): 
        ...
    foo.hello = hello
Re:Metaclasses in Python by d0mine on Friday December 16, 2011 @01:39AM (#3359749)
You should either remove `self` or bind it differently:

  foo = Foo()
  def hello():
      print("hello, %s" % (foo,))
  foo.hello = hello
`foo` is an instance therefore `self == foo` already.

  def hello(self):
      print("hello, %s" % (self,))
  foo.hello = types.MethodType(hello, foo)