Getting not derived members of a class

Franz Steinhaeusler franz.steinhaeusler at gmx.at
Mon Aug 1 11:07:34 EDT 2005


On 1 Aug 2005 07:43:22 -0700, "George Sakkis" <gsakkis at rutgers.edu>
wrote:

>Franz Steinhaeusler wrote:
>
>> Hello NG,
>>
>> I want to retrieve the members of a class
>> with a baseclass.
>> But the problem is, how to get the non derived
>> members.
>>
>> class a:
>>     def who(self):
>>         print "who"
>>     def __init__(self):
>>         self._a = 3
>>
>> class b(a):
>>     def who1(self):
>>         print "who1"
>>     def __init__(self):
>>         a.__init__(self)
>>         self._b = 4
>>
>> y=b()
>>
>> dir (y)
>> ['__doc__', '__init__', '__module__', '_a', '_b', 'who', 'who1']
>>
>>
>> I need a function which lists only the members of
>> the "not derived" class (here class B).
>>
>> _b
>> _who1
>> __init__
>>
>> How can I achieve this?
>> With the introspect module or so?
>
>I believe you can't: Both _a and _b end up in y.__dict__ and there's no
>way to differentiate between the two depending on the time of their
>creation. By the way, these are instance attributes, not class
>attributes, so strictly _b is not a member of B, it's just an instance
>of y. To see why this is the case, check the following valid (though
>highly discouraged) example:
>
>class X:
>    def __init__(self, x):
>        if isinstance(x,str):
>            self._s = x
>        else:
>            self._n = x
>
>x1 = X("1")
>x2 = X(1)
>
>dir(x1)
>['__doc__', '__init__', '__module__', '_s']
>
>dir(x2)
>['__doc__', '__init__', '__module__', '_n']
>
>
>George

Hello George,

thank you for this information.

This is a pity.

The background:
I want to create a code completition for an editor component.
It should distinguish between inherited and non inherited members.
Reason is, that on wxPython, most classes are derived from wxWindow.
For example if I want Code completition for wx.Frame, 
I always get the 200 or so suggestions,
whereby most times, I'm only interested in the possible completions of
wx.Frame and maybe wx.TopLevelWindow.
-- 
Franz Steinhaeusler



More information about the Python-list mailing list