I'm having a problem with calling a function between two python file. I have this file, fileone.py
. This is the main file it runs continuously, then when the if statement becomes true it will do a task then after that it will call the main()
function in the other file, filetwo.py
. Then I'm using break
to stop the loop: (fileone.py)
import filetwo
foo = "sample"
def main():
while True:
if foo == "sample":
#Some task here
print("HELLO")
filetwo.main()
break
main()
And this is the other file, filetwo.py
. It has a main()
function, fileone.py
will call this function to do some task, then after doing the task it will call the main()
function again in the fileone.py
: (filetwo.py)
import fileone
foo = True
def main():
if foo == True:
#Some task here
print("WORLD")
fileone.main()
But, I'm getting this kind of error. AttributeError: module 'filetwo' has no attribute 'main'
. I don't know if my approach of calling the file functions is good or is there a much better way to do it. I tried to use os.system
to run/call the python file but I've read in some articles here that it is much better to call it in a functional way.