我有一些编程经验,但我对 python 很陌生,我正在尝试弄清楚如何使用和导入除主文件以外的 .py 文件中的类。我目前正在使用 netbeans,运行 CPython 3.2.1。
通过我现在的设置,我所有的 .py 文件都在同一个文件夹中。忽略内容实际上是什么,它看起来像这样:
python程序.py
from otherfile import *
obj = classB()
print(obj.run())
def method1():
dostuff
其他文件.py
import pythonprogram
class classA:
def __init__(self, thing1=None, thing2=None):
self.thing1 = thing1
self.thing2 = thing2
def run():
pythonprogram.method1()
return something
class classB(classA):
def __init__(self):
super(thing1=None, thing2=None) #this will be more meaningful later
def run():
do some stuff
return super().run()
到达创建 obj 的行后,我收到以下错误:
Traceback (more recent call last):
C:\users\me\projects\pythonprogram.py in line 4 in <module>
from room import *
C:\users\me\projects\otherfile.py in line 4 in <module>
import pythonprogram
C:\users\me\projects\pythonprogram.py in line 13 in <module>
obj = classB()
由于不熟悉 python,有人可能想让我知道我对 super 的使用是否正确,现在我想到了,但这不是重点(当然也不是我现在正在处理的错误)。
我很难找到与我遇到的错误直接相关的教程或其他问题,但这可能只是因为我对 python 非常不熟悉,以至于我在看到它时忽略了它;因此,如果有人想指出我正确的教程,那也很好。
否则,我只想知道我在如何设置所有内容方面做错了什么,以及我应该如何纠正它。
如果有帮助,我先学习了 Java,并且还可以使用 C# 和 C++。