Re: Python Macros
From: Carlos Ribeiro (carribeiro_at_gmail.com)
Date: 10/06/04
- Next message: gabriele renzi: "Re: Python Macros"
- Previous message: Kent: "Re: Social Analysis and Modeling for Python"
- In reply to: Alex Martelli: "Re: Python Macros"
- Next in thread: Alex Martelli: "Re: Python Macros"
- Reply: Alex Martelli: "Re: Python Macros"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 6 Oct 2004 09:26:30 -0300 To: Alex Martelli <aleaxit@yahoo.com>
On Wed, 6 Oct 2004 10:24:44 +0200, Alex Martelli <aleaxit@yahoo.com> wrote:
> Carlos Ribeiro <carribeiro@gmail.com> wrote:
> ...
> > def __getattr__(self, attrname):
> > # self.__dict__ contains the local dict of Dog
> > message = getattr(self.__dict__, attrname, None)
>
> The only kind of *attributes* you'll find for self.__dict__ are methods
> such as keys, items, copy, and so on. Attributes and items are very
> different things, of course. I suspect this code is a serious bug,
> i.e., the intention is *NOT* to have somedog.copy() return a copy of
> somedog.__dict__ and so on. self.__dict__ will never have attrname as a
> key at this point, either, or else __getattr__ would never have been
> entered in the first place (don't confuse __getattr__ with the rarely
> needed, rarely used __getattribute__!!!). In short, I believe this
> whole part and the following if/else construct just need to be excised.
Thanks (again!). Another dumb mistake. I have mixed up __get__attr,
descriptors, and __getattribute__ in my head, all at once, and messed
up the concepts. Too much reading and too little practice do it :-).
The funny thing is that the code worked as written, at least for my
small test case, because it failed to find the dog.fetch method
anyway.
> If you want to delegate attribute lookup (including method lookup) from
> self to self.owner, ALL you need is:
>
> def __getattr__(self, n): return getattr(self.owner, n)
-- Carlos Ribeiro Consultoria em Projetos blog: http://rascunhosrotos.blogspot.com blog: http://pythonnotes.blogspot.com mail: carribeiro@gmail.com mail: carribeiro@yahoo.com
- Next message: gabriele renzi: "Re: Python Macros"
- Previous message: Kent: "Re: Social Analysis and Modeling for Python"
- In reply to: Alex Martelli: "Re: Python Macros"
- Next in thread: Alex Martelli: "Re: Python Macros"
- Reply: Alex Martelli: "Re: Python Macros"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|