Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32819 > unrolled thread
| Started by | cyberirakli@gmail.com |
|---|---|
| First post | 2012-11-06 05:50 -0800 |
| Last post | 2012-11-06 18:10 -0800 |
| Articles | 9 — 4 participants |
Back to article view | Back to comp.lang.python
Base class and Derived class question cyberirakli@gmail.com - 2012-11-06 05:50 -0800
Re: Base class and Derived class question Dave Angel <d@davea.name> - 2012-11-06 09:13 -0500
Re: Base class and Derived class question cyberirakli@gmail.com - 2012-11-06 07:03 -0800
Re: Base class and Derived class question Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-06 08:34 -0700
Re: Base class and Derived class question cyberirakli@gmail.com - 2012-11-06 08:22 -0800
Re: Base class and Derived class question cyberirakli@gmail.com - 2012-11-06 08:22 -0800
Re: Base class and Derived class question cyberirakli@gmail.com - 2012-11-06 07:03 -0800
Re: Base class and Derived class question cyberirakli@gmail.com - 2012-11-06 07:08 -0800
Re: Base class and Derived class question alex23 <wuwei23@gmail.com> - 2012-11-06 18:10 -0800
| From | cyberirakli@gmail.com |
|---|---|
| Date | 2012-11-06 05:50 -0800 |
| Subject | Base class and Derived class question |
| Message-ID | <fda16cf9-38dd-49ae-9f49-92bc963aac2e@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | Dave Angel <d@davea.name> |
|---|---|
| Date | 2012-11-06 09:13 -0500 |
| Message-ID | <mailman.3324.1352211254.27098.python-list@python.org> |
| In reply to | #32819 |
On 11/06/2012 08:50 AM, cyberirakli@gmail.com wrote: > Hey guys, > I'm trying to understand how is working base class and derived class. in what Python version ? > So, I have to files baseClass.py and derivedClass.py. > baseClass.py : >>>> class baseClass(): How did all those angle brackets get into the file? Are you confusing an interactive interpreter session with running source files? > def bFunction(self): This line isn't indented properly. It must be further from the left margin than the class declaration. > print "We are in a base class" > > derivedClass.py: >>>> import baseClass as baseClassMod > reload(baseClassMod) reload() isn't safe to use, and especially on a module that's been renamed while it was first imported. It's a trick to speed up debugging in the interactive interpreter, and when something goes wrong, you exit the interpreter and try again. > 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 : Again, what are you actually doing? Running that file, or playing around in the interpreter? > 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 : If you run baseClass.py, and get back to the bash prompt, then nothing will affect subsequent tests. >>>> class derivedClass(baseClass): > def dFunction(self): > print "We are in a derived Class" > It works fin Either use the interpreter or run from the shell. This mixing of the two is mighty confusing. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | cyberirakli@gmail.com |
|---|---|
| Date | 2012-11-06 07:03 -0800 |
| Message-ID | <23df4f00-2285-44cc-a9aa-aeb319d000fb@googlegroups.com> |
| In reply to | #32822 |
> 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?
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2012-11-06 08:34 -0700 |
| Message-ID | <mailman.3328.1352216117.27098.python-list@python.org> |
| In reply to | #32824 |
On Tue, Nov 6, 2012 at 8:03 AM, <cyberirakli@gmail.com> 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.
[toc] | [prev] | [next] | [standalone]
| From | cyberirakli@gmail.com |
|---|---|
| Date | 2012-11-06 08:22 -0800 |
| Message-ID | <25864595-7a5b-44c6-b0d3-ee5f57590515@googlegroups.com> |
| In reply to | #32827 |
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.
[toc] | [prev] | [next] | [standalone]
| From | cyberirakli@gmail.com |
|---|---|
| Date | 2012-11-06 08:22 -0800 |
| Message-ID | <mailman.3330.1352218960.27098.python-list@python.org> |
| In reply to | #32827 |
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.
[toc] | [prev] | [next] | [standalone]
| From | cyberirakli@gmail.com |
|---|---|
| Date | 2012-11-06 07:03 -0800 |
| Message-ID | <mailman.3327.1352214191.27098.python-list@python.org> |
| In reply to | #32822 |
> 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?
[toc] | [prev] | [next] | [standalone]
| From | cyberirakli@gmail.com |
|---|---|
| Date | 2012-11-06 07:08 -0800 |
| Message-ID | <775c0f45-ab55-4683-b9f5-2bbed981ee2d@googlegroups.com> |
| In reply to | #32819 |
Just got answer, I didn't call a class it's self. Correct code is:
class derivedClass(baseClassMod.baseClass):
def ......
[toc] | [prev] | [next] | [standalone]
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Date | 2012-11-06 18:10 -0800 |
| Message-ID | <8b17c0fe-b114-4f53-a82e-4439de8a4da4@v9g2000pbi.googlegroups.com> |
| In reply to | #32826 |
On Nov 7, 1:08 am, cyberira...@gmail.com wrote: > 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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web