Robust import style in Python with PyCharm -
i import style robust scripts can run through pycharm run tool, through terminal, , in interactive ipython interpreter. suppose have project looks like
project/ ├── module/ │ ├── __init__.py │ ├── functions.py │ ├── main.py
and suppose functions.py
contains function called a_function
. in main.py
, import (in opinion clearer) absolute import:
from module.functions import a_function
this works when code runs in interactive python console , in pycharm run tool, not if run python module/main.py
terminal (importerror: no module named 'module'
).
i understand why import error , need change can keep import from module.functions import a_function
, avoid import errors when running python module/main.py
.
Comments
Post a Comment