Base class and Derived class question

cyberirakli at gmail.com cyberirakli at gmail.com
Tue Nov 6 11:22:31 EST 2012


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.  



More information about the Python-list mailing list