I have a class which in one of his functions is calling another function from another file that I made:
import test
class myclass:
...
def mainfunc(self):
test.myfunc()
...
start = myclass()
start.mainfunc()
But it gives me this error:
AttributeError: module 'test' has no attribute 'myfunc'
And I don't know why it doesn't call it, even my editor in which I'm working it auto completes the function for me.
How can I fix this?
The test module ( https://docs.python.org/3/library/test.html#module-test ) is used for internal python regression testing, It might be that you are importing that module, rather than your class with the same name.
Simply change the import statement to
from test import myfunc
And inside mainfunc
use
myfunc()
This solution assumes that there is a function myfunc
inside test
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.