FEEDBACK WANTED: Type/class unification

Ben Wolfson rumjuggler at cryptarchy.org
Sat Jul 28 22:12:57 EDT 2001


On Sat, 28 Jul 2001 17:14:38 -0700, Paul Prescod <paulp at ActiveState.com>
wrote:

>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).

I don't see how there could be, since  __getattr__ could define new
attributes when they're requested.

-- 
Barnabas T. Rumjuggler
No man can run so fast that he can escape his own past's projectile vomit.



More information about the Python-list mailing list