3 ms·
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):
by reinhardt 15y ago
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
- d0mine 15y agoYou 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)