Getting the "dir" from the other ancestor ?

Discussion in 'Python' started by Stef Mientki, Apr 28, 2009.

  1. Stef Mientki

    Stef Mientki Guest

    hello,

    I have a class, derived from some user defined class
    (User_Defined_Ancestor) and some basic class (Basic_Ancestor).

    One of the major tasks of the Basic_Ancestor,
    is to hide all kinds of implementation details for the user,
    so the user can concentrate on the functional design.

    One of things I need to know are the methods and attributes of the
    Basic_Ancestor.
    Both classes are dynamic, i.e. attributes are added during run time.

    class Master ( User_Defined_Ancestor, Basic_Ancestor ) :
    def __init__ ( self, *args, **kwargs ) :
    Basic_Ancestor.__init__ ( self, *args, **kwargs )
    .....

    class Basic_Ancestor ( object ) :
    def __init__ ( self, .... ) :
    self.other = dir ( User_Defined_Ancestor )

    def Get_Attributes ( self ) :
    return dir ( self ) - dir ( self.other )


    Now the problem is, I don't know "User_Defined_Ancestor" in Basic_Ancestor.
    I can't pass it through the parameter list, because I use "*args, **kwargs"
    I possibly could use some global variable, but that's not my preference.

    Any other suggestions ?

    thanks,
    Stef Mientki
     
    Stef Mientki, Apr 28, 2009
    #1
    1. Advertising

  2. Stef Mientki

    tuxagb Guest

    On 28 Apr, 15:01, Stef Mientki <> wrote:
    > hello,
    >
    > I have a class, derived from some user defined class
    > (User_Defined_Ancestor) and some basic class (Basic_Ancestor).
    >
    > One of the major tasks of the Basic_Ancestor,
    > is to hide all kinds of implementation details for the user,
    > so the user can concentrate on the functional design.
    >
    > One of things I need to know are the methods and attributes of the
    > Basic_Ancestor.
    > Both classes are dynamic, i.e. attributes are added during run time.
    >
    > class Master ( User_Defined_Ancestor, Basic_Ancestor ) :
    >     def __init__ ( self, *args, **kwargs ) :
    >         Basic_Ancestor.__init__ ( self, *args, **kwargs )
    >         .....
    >
    > class Basic_Ancestor ( object ) :
    >     def __init__ ( self, .... ) :
    >         self.other = dir ( User_Defined_Ancestor )
    >
    >     def Get_Attributes ( self ) :
    >         return dir ( self ) - dir ( self.other )
    >
    > Now the problem is, I don't know "User_Defined_Ancestor" in Basic_Ancestor.
    > I can't pass it through the parameter list, because I use "*args, **kwargs"
    > I possibly could use some global variable, but that's not my preference.
    >
    > Any other suggestions ?
    >
    > thanks,
    > Stef Mientki


    In anytime, if you do dir() in a class B, that extends a class A, you
    have all fields of A also.

    Example:

    >>> class A:

    ... def a(self):
    ... return 0
    >>> class B(A):

    ... def b(self):
    ... return 5
    >>> dir(A)

    [....., 'a']
    >>> dir(B)

    [......, 'a', 'b']

    Hi.
     
    tuxagb, Apr 28, 2009
    #2
    1. Advertising

  3. Stef Mientki

    Stef Mientki Guest

    tuxagb wrote:
    > On 28 Apr, 15:01, Stef Mientki <> wrote:
    >
    >> hello,
    >>
    >> I have a class, derived from some user defined class
    >> (User_Defined_Ancestor) and some basic class (Basic_Ancestor).
    >>
    >> One of the major tasks of the Basic_Ancestor,
    >> is to hide all kinds of implementation details for the user,
    >> so the user can concentrate on the functional design.
    >>
    >> One of things I need to know are the methods and attributes of the
    >> Basic_Ancestor.
    >> Both classes are dynamic, i.e. attributes are added during run time.
    >>
    >> class Master ( User_Defined_Ancestor, Basic_Ancestor ) :
    >> def __init__ ( self, *args, **kwargs ) :
    >> Basic_Ancestor.__init__ ( self, *args, **kwargs )
    >> .....
    >>
    >> class Basic_Ancestor ( object ) :
    >> def __init__ ( self, .... ) :
    >> self.other = dir ( User_Defined_Ancestor )
    >>
    >> def Get_Attributes ( self ) :
    >> return dir ( self ) - dir ( self.other )
    >>
    >> Now the problem is, I don't know "User_Defined_Ancestor" in Basic_Ancestor.
    >> I can't pass it through the parameter list, because I use "*args, **kwargs"
    >> I possibly could use some global variable, but that's not my preference.
    >>
    >> Any other suggestions ?
    >>
    >> thanks,
    >> Stef Mientki
    >>

    >
    > In anytime, if you do dir() in a class B, that extends a class A, you
    > have all fields of A also.
    >

    That's exactly the problem I encounter ;-)
    After some trial and error, I found this solution:

    class Basic_Ancestor ( object ) :
    def __init__ ( self, .... ) :
    # Collect all methods and attributes of other classes
    self.Exclude_Dir = []
    Base_Classes = self.__class__.__bases__
    for BC in Base_Classes :
    if BC != My_Control_Class :
    self.Exclude_Dir += dir ( BC )


    cheers,
    Stef
     
    Stef Mientki, Apr 28, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    Sub Dir, Virtual dir, what do I use?

    =?Utf-8?B?UnVkeQ==?=, Jun 12, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    431
    =?Utf-8?B?UnVkeQ==?=
    Jun 12, 2005
  2. werD
    Replies:
    2
    Views:
    1,918
    Peter Flynn
    Aug 28, 2006
  3. Luis P. Mendes
    Replies:
    3
    Views:
    354
    Bruno Desthuilliers
    Sep 15, 2006
  4. Matthew Denner
    Replies:
    1
    Views:
    186
  5. Kga Agk
    Replies:
    2
    Views:
    153
    Kga Agk
    Jun 29, 2009
Loading...

Share This Page