I have a doubt about import statements. I encountered the same problem during ex46 when trying to install my package using setup.py
I read several similar topics in the forum and in other forums but I’m still not sure about this.
So, this is my tree:
ex48/ ex48/ __init__.py lexicon.py pars.py tests/ lexicon_tests.py pars_tests.py
The import statement in pars.py is:
from ex48.lexicon import scan
In pars_tests.py is:
from ex48 import pars
So far everything works fine. The tests run and we are happy.
But many times while I’m writing the code I want to run the pars.py script directly from the command line or the IDE to check what I just wrote.
But this will raise a ModuleNotFoundError unless I change the import statement in pars.py to:
from lexicon import scan
But of course this will then raise the error when I tried to run the tests.
Is there a way to keep both options available? (Run the tests successfully and also be able to run the scripts directly in the shell)
Thanks for your help!