我对从另一个文件导入方法有点困惑。Python,导入文件中的init方法
我在写一个从python-automata
导入的Python脚本。我已经下载了该文件,并在我的../Python/
目录中存储了DFA.py
和myfile.py
。
在myfile.py
我这个写在上面:
import DFA
正如我下面什么写在python tutorial,我认为在myfile.py
我可以使用DFA.py
定义的任何方法。该文件有一个名为__init__
的方法,该方法需要5个参数并初始化DFA
。然后,我写这篇文章myfile.py
:
DFA.__init__(states, alphabet, delta(states, alphabet), start, accepts)
凡州,字母,三角洲,启动和接受都是基本的清单/我在myfile.py已经初始化功能。
但是当我尝试运行myfile.py,我得到这个错误:
Traceback (most recent call last):
File "myfile.py", line 21, in <module>
DFA.__init__(states, alphabet, delta(states, alphabet), start, accepts)
TypeError: module.__init__() takes at most 2 arguments (5 given)
我不知道为什么它说,它需要两个参数,当DFA.py
其定义为以在5个参数。在DFA.py
,我看到:
class DFA:
def __init__(self, states, alphabet, delta, start, accepts):
...
好像我之前遇到过类似的错误(见Python import issue和Python classes and __init__ method),但我不认为我需要在这里解决继承。
谢谢!这很好用!和+1给我额外的链接来阅读。 – TakeS