I started learning python in the last few days, and while studying object oriented programming, I am having problems. I use Eclipse when I run the pydev plugin, I run the beta version of python 3.3 and use the 64-bit Windows system.
I can initialize the class perfectly and use any methods inside it until I try to extend the superclass (each class that I encoded in a different source file) For example, the following code compiles and works fine.
class pythonSuper: string1 = "hello" def printS(): print pythonSuper.string1
and code to access and run ...
from stackoverflow.questions import pythonSuper class pythonSub: pysuper = pythonSuper.pythonSuper() pysuper.printS()
As I said, this works. The following code is not
class pythonSuper: """Same superclass as above. unmodified, except for the spacing""" string1 = "hello" def printS(self): print(pythonSuper.string1)
Well, thatβs not entirely true. The superclass is absolutely beautiful, at least as far as I know. This is a subclass that suffers from
from stackoverflow.questions import pythonSuper class pythonSub(pythonSuper): pass pythonObject = pythonSub() pythonSub.pythonSuper.printS()
when starting a subclass, Eclipse produces this error
Traceback (most recent call last): File "C:\Users\Anish\workspace\Python 3.3\stackoverflow\questions\pythonSub.py", line 7, in <module> class pythonSub(pythonSuper): TypeError: module.__init__() takes at most 2 arguments (3 given)
I have no idea what is going on. I studied python from thenewboston tutorials, but they are deprecated (I think its tutorial code uses python version 2.7). It also encodes IDLE, which means its classes are all contained in a single file. However, the mines are encoded in their own files. This means that I have no idea whether the code errors that I receive are the result of outdated syntax or lack of knowledge in this language. But I was distracted. If someone can send a message using a solution and / or explanation of why the code is going wrong and what I can do to fix it. An explanation would be preferable. I would rather know what I'm doing wrong, so I can avoid and fix the problem in such situations than just copy and paste the code and see how it works. Thank you and I look forward to hearing your answers.