Inheritence confusion (was Re: Deeply-nested class layout suggestions wanted)

Kirk Strauser kirk at strauser.com
Fri Jun 11 15:10:08 EDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

As a final concrete example, I whipped up a few little skeleton classes like
so:

    Generic
    |-- Subclass
    |   |-- __init__.py
    |   |-- a.py
    |   `-- b.py
    |-- __init__.py
    |-- a.py
    `-- b.py

Generic/a.py

    from b import b

    class a:
        def __init__(self):
            test = b()

Generic/b.py

    class b:
        def __init__(self):
            print 'In Generic.b'

Generic/Subclass/a.py

    import Generic.a

    class a(Generic.a.a):
        pass

Generic/Subclass/b.py

    import Generic.b

    class b(Generic.b.b):
        def __init__(self):
            print 'In Subclass.b'

Now, whether I instantiate Generic.a.a or Generic.Subclass.a.a, it
references the Generic.b module instead of the Generic.Subclass.b module:

    >>> import Generic.a
    >>> Generic.a.a()
    In Generic.b
    <Generic.a.a instance at 0x811dd04>
    >>> import Generic.Subclass.a
    >>> Generic.Subclass.a.a()
    In Generic.b
    <Generic.Subclass.a.a instance at 0x811f96c>
    >>>

I'm completely lost.  What do I have to do to get the subclasses to use
modules at their own level instead of where the defined __init__ function
happens to be?
- -- 
Kirk Strauser
The Strauser Group
Open. Solutions. Simple.
http://www.strausergroup.com/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAygLp5sRg+Y0CpvERAsC/AJ4yKvfmVXp3ppEizUTq3k/8PzJqsQCcCWin
25z6qeK3UokOPcsegW+YVes=
=gsuH
-----END PGP SIGNATURE-----



More information about the Python-list mailing list