FEEDBACK WANTED: Type/class unification
Paul Prescod
paulp at ActiveState.com
Sat Jul 28 16:07:32 EDT 2001
I'm reading the section on the introspection API but I don't understand
something.
1. If I am sitting at an interpreter prompt and I have an object how do
I figure out the complete list of currently available attributes
available on that object.
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?
If I understand correctly, doing this is not sufficient:
>>> T = foo.__class__
>>> T
<type 'Foo'>
>>> dir(T)
I don't think that this will get base class attributes or attributes
hidden in __getattr__. And even if it did, it would be nice to have a
single API that combined instance attributes and class attributes
according to the fallback rules. i.e. I'd like something as close to
this as is realistically possible:
def attrs(x):
return [y for y in all_possible_strings if hasattr(x, y)]
--
Take a recipe. Leave a recipe.
Python Cookbook! http://www.ActiveState.com/pythoncookbook
More information about the Python-list
mailing list