Chris Mellon a écrit :
On Thu, 2007-10-25 at 23:13 +0200, Bruno Desthuilliers wrote:
snip excellent breakdown
blush /
Dynamically adding methods to classes is pretty
straightforward, the tricky point is to dynamically add methods to
instances, since the descriptor protocol is only
Thank you all for the detailed replies, I appreciate it. I only read
up on this yesterday morning, but I feel I've gotten a lot of insight
in a short time thanks to your contributions to this thread. Useful
all around!
Adam
On Oct 26, 2:50 am, Bruno Desthuilliers bruno.
[EMAIL PROTECTED]
On Oct 25, 5:07 pm, Adam Donahue [EMAIL PROTECTED] wrote:
As an exercise I'm attempting to write a metaclass that causes an
exception to be thrown whenever a user tries to access
'attributes' (in the traditional sense) via a direct reference.
Well, now thanks to Bruno and the others you know
As an exercise I'm attempting to write a metaclass that causes an
exception to be thrown whenever a user tries to access
'attributes' (in the traditional sense) via a direct reference.
Consider:
class X( object ):
y = 'private value'
def get_y( self ): return self.y
Normally
Adam Donahue a écrit :
As an exercise I'm attempting to write a metaclass that causes an
exception to be thrown whenever a user tries to access
'attributes' (in the traditional sense) via a direct reference.
I guess you're new to Python, and coming from either C++ or Java. Am I
wrong ?-)
And
Bruno,
I appreciate your attempt to answer my questions below, although I
think my main point was lost amongst all your commentary and
assumptions. :^) I'm not inexperienced, but I take the blame for
the rambling initial post, though, which probably lead to the
confusion.
So let me be more
Adam Donahue wrote:
class X( object ):
... def c( self ): pass
...
X.c
unbound method X.c
x = X()
x.c
bound method X.c of __main__.X object at 0x81b2b4c
If my interpretation is correct, the X.c's __getattribute__ call knows
the attribute reference is via a class, and thus returns
Adam Donahue a écrit :
Bruno,
I appreciate your attempt to answer my questions below, although I
think my main point was lost amongst all your commentary and
assumptions. :^)
Possibly. I sometimes tend to get a bit verbose !-)
I'm not inexperienced,
Obviously not.
but I take the
On Thu, 2007-10-25 at 23:13 +0200, Bruno Desthuilliers wrote:
snip excellent breakdown
The logical next question then is how does one best add a new method
to this class so that future references to x.set_x() and X.set_x will
properly resolve? It seems the answer would be to somehow add