On Sun, 07 Apr 2013 11:41:46 +0100, Arnaud Delobelle wrote: > On 7 April 2013 10:50, Helmut Jarausch <jarau...@skynet.be> wrote: >> Hi, >> >> I'm trying to port a class to Python3.3 which contains >> >> class Foo : >> .... >> def to_binary(self, *varargs, **keys): >> .... >> >> .... >> self.to_binary = new.instancemethod(to_binary, self, >> self.__class__) > > `self` isn't bound in this lexical scope (the class scope). Or is your > indentation incorrect? However, if this statement was within the > `to_binary` method, then `to_binary` wouldn't be bound so I can't make a > reasonable guess. > >> # Finally call it manually return apply(self.to_binary, varargs, >> keys) >> > [...]
Sorry, the excerpt wasn't complete (it's not my code): Here a more complete excerpt: class Foo : .... def to_binary(self, *varargs, **keys): .... code= ... args= ... # Add function header code = 'def to_binary(self, %s):\n' % ', '.join(args) + code exec(code) self.to_binary = new.instancemethod(to_binary, self, self.__class__) return self.to_binary(*varargs, **keys) -- http://mail.python.org/mailman/listinfo/python-list