is there a way to import multiple python files into a main python file?
I have a bunch of py files and each one has to run in the main python file and the data are s
The syntax for importing your_filename.py
, assuming it is in the same directory, is
import your_filename
In your case, it would be
import light
Note the absence of .py
.
If your file is in a different directory, you'll need to do:
import sys
sys.path.append('path/to/dir/containing/your_filename.py')
import your_filename
Note that appending to sys.path
is dangerous, and should not be done unless you know what you're doing.
Read more at the official docs for import.