[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
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]
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
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
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
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
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
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
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
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
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.
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
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
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
14 matches
Mail list logo