FEEDBACK WANTED: Type/class unification

William Tanksley wtanksle at
Sun Jul 29 00:24:22 CEST 2001

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.  Such an
object, unmodified, would not support introspection.

Can anyone who's used __getattr__ speak up and say whether any
introspection support would be possible or useful?

>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


-William "Billy" Tanksley

More information about the Python-list mailing list