How to import another python script (.py) into main python file
To include the dictionary, you could do this if your file location is in different directory (with caution of path.append as @Coldspeed mentioned):
import sys
sys.path.append("path/foo/bar/")
from light import *
If it is in same directory as current directory, you could just do:
from light import *
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.