I have two files, say main.py and foo.py. When I import foo in main, I thought the lines in foo.py that not in a function automaticly run.
But when I add an executable to PATH in foo, and call main of foo that involves that executable which should be in PATH, it gives an error: geckodriver executable must be in PATH. If I add it to PATH right after the imports in main.py, it works correctly. Here are the sample codes:
main.py:
# some imports
from foo_file import foo
foo.main()
foo.py:
import os
FILENAME = os.path.dirname(os.path.abspath(__file__))
os.environ["PATH"] += os.pathsep + os.path.join(FILENAME, "assets")
def main():
# some work involves selenium
Why the first try doesn't work and gives the error? Thanks.