On Dec 16, 2005, at 6:26 PM, [EMAIL PROTECTED] wrote:
> You can also just use:
>
> t.dynamic = dynamic.__get__(t)
OK, I've tried that, and it does indeed work well. I've never
had occasion to use descriptors before, and while it's clear what's
going on, it still has a 'magical' feel to i
On Dec 16, 2005, at 7:55 AM, Antoon Pardon wrote:
> But this will make the function a method to all instances of the
> class.
> Is that what you want? From your first post I had the impression you
> only wanted the function to be the method of one particular instance.
Yes, you're correct -
You can also just use:
t.dynamic = dynamic.__get__(t)
--
http://mail.python.org/mailman/listinfo/python-list
Antoon Pardon <[EMAIL PROTECTED]> wrote:
> Op 2005-12-15, Ed Leafe schreef <[EMAIL PROTECTED]>:
>> On Dec 15, 2005, at 11:51 AM, Lawrence Oluyede wrote:
>>
So? Am I nuts? Or is this possible?
>>>
>>> Yes it is, use exec() to turn your string in valid Python code
>>> and bind the dynamic f
To avoid that:
- subclass Test first
class SubclassTest(T):
pass
- assign the method to SubclassTest's attribute,
SubclassTest.dynamic = dynamic
- then assign the new class to magic variable __class__ :
t.__class__ = SubclassTest
t.dynamic()
Antoon Pardon wrote:
> But this will make the
Op 2005-12-15, Ed Leafe schreef <[EMAIL PROTECTED]>:
> On Dec 15, 2005, at 11:51 AM, Lawrence Oluyede wrote:
>
>>> So? Am I nuts? Or is this possible?
>>
>> Yes it is, use exec() to turn your string in valid Python code
>> and bind the dynamic function as a method of class Test
>>
>> xx = """d
On Dec 15, 2005, at 11:51 AM, Lawrence Oluyede wrote:
>> So? Am I nuts? Or is this possible?
>
> Yes it is, use exec() to turn your string in valid Python code
> and bind the dynamic function as a method of class Test
>
> xx = """def dynamic(self):
> print "dynamic", self.testAtt
> """
>
Il 2005-12-15, Ed Leafe <[EMAIL PROTECTED]> ha scritto:
> Here's what I'm trying to do; please let me know if I'm nuts or
> not.
>
> Given a string consisting of the code you would normally define
> in a class's method, add that compiled code to an instance of that
> class so that i
Here's what I'm trying to do; please let me know if I'm nuts or
not.
Given a string consisting of the code you would normally define
in a class's method, add that compiled code to an instance of that
class so that it can be called just like any other bound method.
Here's an examp