FEEDBACK WANTED: Type/class unification
Paul Prescod
paulp at ActiveState.com
Sat Jul 28 20:14:38 EDT 2001
William Tanksley wrote:
>
> On Sat, 28 Jul 2001 13:07:32 -0700, Paul Prescod wrote:
> >2. If I have an object that hides its attributes behind an __getattr__,
> >is there any way to tweak the list returned by the API described above?
>
> Not without the object's cooperation -- it's not even theoretically
> possible to figure out what attributes __getattr__ might support.
I am asking whether there is a way for the object to cooperate.
>...
> >def attrs(x):
> > return [y for y in all_possible_strings if hasattr(x, y)]
>
> Yes, that would work, for certain values of "work". all_possible_strings
> is a pretty simple generator. So is attrs(), actually.
>
> def attrs(x):
> for y in all_possible_strings():
> if hasattr(x,y): yield y
>
> Amusing.
I wasn't being theoretical. I was asking whether there is a function,
method or parameter with those semantics (and obviously a more sane
implementation).
--
Take a recipe. Leave a recipe.
Python Cookbook! http://www.ActiveState.com/pythoncookbook
More information about the Python-list
mailing list