Base class and Derived class question

2012-11-06 Thread 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 : 
[CODE]class baseClass():
def bFunction(self):
print "We are in a base class"[/CODE]

derivedClass.py:
[CODE]import baseClass as baseClassMod
reload(baseClassMod)

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

buwhen I'm trying to run derivedClass.py I get this error :
[CODE][COLOR=Red]TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)[/COLOR][/CODE]

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"[/CODE]
It works fine
-- 
http://mail.python.org/mailman/listinfo/python-list


Base class and Derived class question

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

derivedClass.py:
>>>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 :
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 :
>>>class derivedClass(baseClass):
def dFunction(self):
print "We are in a derived Class"
It works fin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Base class and Derived class question

2012-11-06 Thread 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][/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? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Base class and Derived class question

2012-11-06 Thread cyberirakli
Just got answer, I didn't call a class it's self.  Correct code is:
class derivedClass(baseClassMod.baseClass):
def ..
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Base class and Derived class question

2012-11-06 Thread cyberirakli
On Tuesday, November 6, 2012 4:35:47 PM UTC+1, Ian wrote:
> 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][/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 Tuesday, November 6, 2012 4:35:47 PM UTC+1, Ian wrote:
> 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][/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 Tuesday, November 6, 2012 4:35:47 PM UTC+1, Ian wrote:

> 
> > I've used angle brackets just for posting here,becauze this forum doesn't 
> > support [code][/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 will need adding 
some new modules. So, for better organisation of all this stuff I have put them 
in separate files.  
-- 
http://mail.python.org/mailman/listinfo/python-list