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 kn
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 wrote:
> Chris Mellon a écrit
Chris Mellon a écrit :
> On Thu, 2007-10-25 at 23:13 +0200, Bruno Desthuilliers wrote:
>
>> Dynamically adding methods to classes is pretty
>> straightforward, the tricky point is to dynamically add methods to
>> instances, since the descriptor protocol is only triggered for class
>> attribu
On Thu, 2007-10-25 at 23:13 +0200, Bruno Desthuilliers wrote:
> > 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 to
> > X.__dict__ a
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 tak
Adam Donahue wrote:
class X( object ):
> ... def c( self ): pass
> ...
X.c
>
x = X()
x.c
> >
>
> If my interpretation is correct, the X.c's __getattribute__ call knows
> the attribute reference is via a class, and thus returns an unbound
> method (though it does convert th
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 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 ?-)
A
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