I'm getting a little confused about importing methods from another file.
I'm writing a Python script that imports from python-automata
. I've downloaded the file and in my ../Python/
directory, I have DFA.py
and myfile.py
stored.
In myfile.py
I have this written on top:
import DFA
As I'm following what's written in the python tutorial, I assume that in myfile.py
I can use any method defined in DFA.py
. That file has a method called __init__
which takes in 5 arguments and initializes a DFA
. Then I write this in myfile.py
:
DFA.__init__(states, alphabet, delta(states, alphabet), start, accepts)
Where states, alphabet, delta, start, and accepts are all basic lists/functions that I have initialized in myfile.py.
But then when I try to run myfile.py, I get this error:
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)
I'm not sure why it says it takes 2 arguments, when DFA.py
defines it as taking in 5 arguments. In DFA.py
, I see:
class DFA:
def __init__(self, states, alphabet, delta, start, accepts):
...
It seems like a similar errors I encountered earlier (see Python import issue and Python classes and __init__ method) but I don't think that I need to deal with inheritance here.