Re: adding methods at runtime

2008-01-11 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Can I access the class attributes from a method added at runtime? Of course. > (My > experience says no.) So there's something wrong with your experience !-) > I experimented with the following code: > > > class myclass(object): > myattr = "myattr" > > inst

Re: adding methods at runtime

2008-01-11 Thread John Machin
On Jan 11, 10:44 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Thu, 10 Jan 2008 14:55:18 -0800, [EMAIL PROTECTED] wrote: > > Can I access the class attributes from a method added at runtime? (My > > experience says no.) > > I experimented with the following code: > > > [Code snipped]

Re: adding methods at runtime

2008-01-10 Thread Marc 'BlackJack' Rintsch
On Thu, 10 Jan 2008 14:55:18 -0800, [EMAIL PROTECTED] wrote: > Can I access the class attributes from a method added at runtime? (My > experience says no.) > I experimented with the following code: > > [Code snipped] > > So it seems to me, if you add a method to an instance, the method will > no

adding methods at runtime

2008-01-10 Thread [EMAIL PROTECTED]
Can I access the class attributes from a method added at runtime? (My experience says no.) I experimented with the following code: class myclass(object): myattr = "myattr" instance = myclass() def method(x): print x instance.method = method instance.method("hello world") inst2 = myclas

Re: adding methods at runtime and lambda

2007-05-07 Thread Mike
On May 4, 5:46 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > Mike wrote: > > I just realized in working with this more that the issues I was having > > with instancemethod and other things seems to be tied solely to > > What you describe below is a function that happens to be an attribute of an > in

Re: adding methods at runtime and lambda

2007-05-04 Thread Peter Otten
Mike wrote: > I just realized in working with this more that the issues I was having > with instancemethod and other things seems to be tied solely to What you describe below is a function that happens to be an attribute of an instance. There are also "real" instance methods that know about "thei

Re: adding methods at runtime and lambda

2007-05-04 Thread Mike
On May 4, 2:05 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > Mike wrote: > > staticmethod makes the function available to the whole class according > > to the docs. What if I only want it to be available on a particular > > instance? Say I'm adding abilities to a character in a game and I want > > t

Re: adding methods at runtime and lambda

2007-05-04 Thread Peter Otten
Mike wrote: > staticmethod makes the function available to the whole class according > to the docs. What if I only want it to be available on a particular > instance? Say I'm adding abilities to a character in a game and I want > to give a particular character the ability to 'NukeEverybody'. I don

Re: adding methods at runtime and lambda

2007-05-04 Thread Mike
On May 3, 11:25 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 03 May 2007 16:52:55 -0300, Mike <[EMAIL PROTECTED]> escribió: > > > I was messing around with adding methods to a class instance at > > runtime and saw the usual code one finds online for this. All the > > examples I saw

Re: adding methods at runtime and lambda

2007-05-03 Thread Gabriel Genellina
En Thu, 03 May 2007 16:52:55 -0300, Mike <[EMAIL PROTECTED]> escribió: > I was messing around with adding methods to a class instance at > runtime and saw the usual code one finds online for this. All the > examples I saw say, of course, to make sure that for your method that > you have 'self' as

Re: adding methods at runtime and lambda

2007-05-03 Thread ici
On May 3, 10:52 pm, Mike <[EMAIL PROTECTED]> wrote: > I was messing around with adding methods to a class instance at > runtime and saw the usual code one finds online for this. All the > examples I saw say, of course, to make sure that for your method that > you have 'self' as the first parameter.

Re: adding methods at runtime and lambda

2007-05-03 Thread James Stroud
Mike wrote: > I was messing around with adding methods to a class instance at > runtime and saw the usual code one finds online for this. All the > examples I saw say, of course, to make sure that for your method that > you have 'self' as the first parameter. I got to thinking and thought > "I have

Re: adding methods at runtime and lambda

2007-05-03 Thread Mike
In the above example 'addm' should be 'AddMethod' superdict = AddMethod(dict(), lambda self, d: myUtils.HasDrive(d),"hasdrive") -- http://mail.python.org/mailman/listinfo/python-list

adding methods at runtime and lambda

2007-05-03 Thread Mike
I was messing around with adding methods to a class instance at runtime and saw the usual code one finds online for this. All the examples I saw say, of course, to make sure that for your method that you have 'self' as the first parameter. I got to thinking and thought "I have a lot of arbitrary me