#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Base class and Derived class(noob question)


    Hey guys,
    I'm trying to understand how is working base class and derived class.
    So, I have to files baseClass.py and derivedClass.py.
    baseClass.py :
    Code:
    class baseClass():
        def bFunction(self):
            print "We are in a base class"
    derivedClass.py:
    Code:
    import baseClass as baseClassMod
    reload(baseClassMod)
    
    class derivedClass(baseClassMod):
        def dFunction(self):
            print "We are in a derived Class"
    buwhen I'm trying to run derivedClass.py I get this error :
    Code:
    TypeError: Error when calling the metaclass bases
        module.__init__() takes at most 2 arguments (3 given)
    Interesting thing is that if I run baseClass.py and then run :
    Code:
    class derivedClass(baseClass):
        def dFunction(self):
            print "We are in a derived Class"
    It works fine
  2. #2
  3. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Norcross, GA (again)
    Posts
    1,804
    Rep Power
    1569
    The issue is that you are changing the name of the imported module, but not the imported class. In order to do what you seem to want, you would either have to refer to the BaseClassMod explicitly:
    Code:
    import baseClass as baseClassMod
    reload(BaseClassMod)
    
    class derivedClass(baseClassMod.baseClass):
        def dFunction(self):
            print "We are in a derived Class"
    or import the class name with an as clause:
    Code:
    from baseClass import baseClass as baseClassMod
    reload(BaseClassMod)
    
    class derivedClass(baseClassMod):
        def dFunction(self):
            print "We are in a derived Class"

    Comments on this post

    • Cyberika agrees : Realy elpfull post! Thank you!
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    Thank you! Now it's clear.

IMN logo majestic logo threadwatch logo seochat tools logo