Base class and Derived class question

C

cyberirakli

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 :def bFunction(self):
print "We are in a base class"

derivedClass.py: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 :
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 :def dFunction(self):
print "We are in a derived Class"
It works fin
 
C

cyberirakli

in what Python version ?

Python 2.7.3

How did all those angle brackets get into the file? Are you confusing

an interactive interpreter session with running source files?

I've used angle brackets just for posting here,becauze this forum doesn't support
Code:

I have a file called baseClass.py with code abouve and indentation is correct.
Then I open python IDLE and type :
import baseClass as baseClassMod
reload(baseClassMod

class derivedClass(baseClassMod):
def dFunction(self):
print "We are in a derived Class"

After that i get the error above. But if I paste in Python IDLE a code from baseClass.py and just run:
class derivedClass(baseClass):
def dFunction(self):
print "We are in a derived Class"

it works perfectly.
Why happen this?
 
C

cyberirakli

in what Python version ?

Python 2.7.3

How did all those angle brackets get into the file? Are you confusing

an interactive interpreter session with running source files?

I've used angle brackets just for posting here,becauze this forum doesn't support
Code:

I have a file called baseClass.py with code abouve and indentation is correct.
Then I open python IDLE and type :
import baseClass as baseClassMod
reload(baseClassMod

class derivedClass(baseClassMod):
def dFunction(self):
print "We are in a derived Class"

After that i get the error above. But if I paste in Python IDLE a code from baseClass.py and just run:
class derivedClass(baseClass):
def dFunction(self):
print "We are in a derived Class"

it works perfectly.
Why happen this?
 
C

cyberirakli

Just got answer, I didn't call a class it's self. Correct code is:
class derivedClass(baseClassMod.baseClass):
def ......
 
I

Ian Kelly

I've used angle brackets just for posting here,becauze this forum doesn't support
Code:

This is a Usenet group, not a web forum.
Just got answer, I didn't call a class it's self. Correct code is:
class derivedClass(baseClassMod.baseClass):
def ......

Better style would be to import the class from the module in the first place:

from baseClass import baseClass

# ...

class derivedClass(baseClass):
# ...

Better yet would be to put both classes in the same file in the first
place. Python isn't Java, where each class is an independent
compilation unit. There is no reason to put each class in its own
separate module, and it tends to cause namespace confusion as you have
discovered.
 
C

cyberirakli

On Tue, Nov 6, 2012 at 8:03 AM,
I've used angle brackets just for posting here,becauze this forum doesn't support
Code:



This is a Usenet group, not a web forum.


Just got answer, I didn't call a class it's self. Correct code is:
class derivedClass(baseClassMod.baseClass):
def ......



Better style would be to import the class from the module in the first place:



from baseClass import baseClass



# ...



class derivedClass(baseClass):

# ...



Better yet would be to put both classes in the same file in the first

place. Python isn't Java, where each class is an independent

compilation unit. There is no reason to put each class in its own

separate module, and it tends to cause namespace confusion as you have

discovered.



On Tue, Nov 6, 2012 at 8:03 AM,
I've used angle brackets just for posting here,becauze this forum doesn't support
Code:



This is a Usenet group, not a web forum.


Just got answer, I didn't call a class it's self. Correct code is:
class derivedClass(baseClassMod.baseClass):
def ......



Better style would be to import the class from the module in the first place:



from baseClass import baseClass



# ...



class derivedClass(baseClass):

# ...



Better yet would be to put both classes in the same file in the first

place. Python isn't Java, where each class is an independent

compilation unit. There is no reason to put each class in its own

separate module, and it tends to cause namespace confusion as you have

discovered.


I've used angle brackets just for posting here,becauze this forum doesn't support
Code:



This is a Usenet group, not a web forum.


Just got answer, I didn't call a class it's self. Correct code is:
class derivedClass(baseClassMod.baseClass):
def ......



Better style would be to import the class from the module in the first place:



from baseClass import baseClass



# ...



class derivedClass(baseClass):

# ...



Better yet would be to put both classes in the same file in the first

place. Python isn't Java, where each class is an independent

compilation unit. There is no reason to put each class in its own

separate module, and it tends to cause namespace confusion as you have

discovered.



Thank you for reply. Of course, import just a class from the module. The reason of have each class in separate file is that I have a base class with basic functionality and a lot of derived classes from it with custom functionality for each class. Also, the program is modular and periodically willneed adding some new modules. So, for better organisation of all this stuff I have put them in separate files.
 
C

cyberirakli

On Tue, Nov 6, 2012 at 8:03 AM,
I've used angle brackets just for posting here,becauze this forum doesn't support
Code:



This is a Usenet group, not a web forum.


Just got answer, I didn't call a class it's self. Correct code is:
class derivedClass(baseClassMod.baseClass):
def ......



Better style would be to import the class from the module in the first place:



from baseClass import baseClass



# ...



class derivedClass(baseClass):

# ...



Better yet would be to put both classes in the same file in the first

place. Python isn't Java, where each class is an independent

compilation unit. There is no reason to put each class in its own

separate module, and it tends to cause namespace confusion as you have

discovered.



On Tue, Nov 6, 2012 at 8:03 AM,
I've used angle brackets just for posting here,becauze this forum doesn't support
Code:



This is a Usenet group, not a web forum.


Just got answer, I didn't call a class it's self. Correct code is:
class derivedClass(baseClassMod.baseClass):
def ......



Better style would be to import the class from the module in the first place:



from baseClass import baseClass



# ...



class derivedClass(baseClass):

# ...



Better yet would be to put both classes in the same file in the first

place. Python isn't Java, where each class is an independent

compilation unit. There is no reason to put each class in its own

separate module, and it tends to cause namespace confusion as you have

discovered.


I've used angle brackets just for posting here,becauze this forum doesn't support
Code:



This is a Usenet group, not a web forum.


Just got answer, I didn't call a class it's self. Correct code is:
class derivedClass(baseClassMod.baseClass):
def ......



Better style would be to import the class from the module in the first place:



from baseClass import baseClass



# ...



class derivedClass(baseClass):

# ...



Better yet would be to put both classes in the same file in the first

place. Python isn't Java, where each class is an independent

compilation unit. There is no reason to put each class in its own

separate module, and it tends to cause namespace confusion as you have

discovered.



Thank you for reply. Of course, import just a class from the module. The reason of have each class in separate file is that I have a base class with basic functionality and a lot of derived classes from it with custom functionality for each class. Also, the program is modular and periodically willneed adding some new modules. So, for better organisation of all this stuff I have put them in separate files.
 
A

alex23

Just got answer, I didn't call a class it's self.  Correct code is:
class derivedClass(baseClassMod.baseClass):
    def ......

Incidentally, this is why it's recommended to give modules lowercase
names - baseclass - and classes camelcased ones - BaseClass. It makes
it more obvious to what you're holding a reference.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top