我有 2 个 python 文件。一个声明了一个名为语言的类:
class language:
def __init__(self, name, letters, elements, grammar):
self.n = name
self.l = letters
self.e = elements
self.g = grammar
我将其保存为:“language_class.py”。然后我尝试通过执行以下操作将其导入另一个名为“turkish.py”的程序:
turkish = __import__('language_class').language(self,"Turkish",turkish_latin,turkish_grammar).turkish
当我运行 language_class.py 时,我没有遇到任何问题,但是当我运行 turkish.py 时:
Traceback (most recent call last):
File "C:\Users\Ahmet\Desktop\Google Apps\transalator\The Transalator\Recources\Languages\turkish.py", line 1, in <module>
turkish = __import__('language_class').language(self,"Turkish",turkish_latin,turkish_grammar).turkish
NameError: name 'self' is not defined
但是 self 是明确定义的。这是某种错误,还是我做错了?感谢您的帮助,即使我比您看到此消息早几个小时感谢您:D