python - load py file from path/folder -
i busy calculations in python , therefore have bunch of scripts. have tried clean thru 2 folders named scripts , tests. have problem main python file don't recognize scripts in subfolders.
import filename don't work anny more. when in git files looks don mention paths , still works.
had looked @ this se question gave me error (importerror: no module named "filename")
what have in main script, subfolder or files in subfolders.
my scripts no classes yet... not become classes. generic solution best
you can relative imports are. let's assume you're importing file /home/janbert/projects/test/test.py
if want import /home/janbert/projects/test/subdir/file.py write:
from subdir import file and if want import /home/janbert/projects/otherproject/subdir/file.py write:
from ..otherproject.subdir import file just remember each python package (ie folder) must have file named __init__.py (which can empty), otherwise can not import package.
Comments
Post a Comment