Re: Python Macros

From: Carlos Ribeiro (carribeiro_at_gmail.com)
Date: 10/06/04


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


Relevant Pages

  • Re: LambdaRogue v0.3 (gamma 1)
    ... blog and binary downloads are provided here: ... Source code and older releases can be found on LambdaRogue's SourceForge ... unlikely that it's bug free. ... couldn't figure out the diagonal scheme.) ...
    (rec.games.roguelike.development)
  • [release] LambdaRogue v0.3 (gamma 1)
    ... blog and binary downloads are provided here: ... Source code and older releases can be found on LambdaRogue's SourceForge page: ... I testet the game several times on Linux and Windows, both in SDL and in console mode, but it's unlikely that it's bug free. ... (There will also be a small update to the data files soon, available as patch from the LR blog, but that's nothing critical; just some text files that most people won't read anyhow.) ...
    (rec.games.roguelike.development)
  • [release] LambdaRogue v0.3 (gamma 1)
    ... blog and binary downloads are provided here: ... Source code and older releases can be found on LambdaRogue's SourceForge page: ... I testet the game several times on Linux and Windows, both in SDL and in console mode, but it's unlikely that it's bug free. ... (There will also be a small update to the data files soon, available as patch from the LR blog, but that's nothing critical; just some text files that most people won't read anyhow.) ...
    (rec.games.roguelike.misc)
  • [release] LambdaRogue v0.3 (gamma 1)
    ... blog and binary downloads are provided here: ... Source code and older releases can be found on LambdaRogue's SourceForge ... unlikely that it's bug free. ... (There will also be a small update to the data files soon, ...
    (rec.games.roguelike.announce)
  • Re: Health care AO (after Obama) MUST SEE!
    ... I posted this vid on my Facebook and Myspace pages, ... blog. ... I suspect we will not get *one* reply from any of the Liberals in ...
    (rec.sport.pro-wrestling)