I know what your getting at, this will work if you want to have variables in
the included file in scope in the caller of 'include', just insert it as normal
python.
Though I prefer this version as it is simpler and less error prone.
with open('myfile.py') as f: exec(f.read())
Basically, it inc
The recommended way to import files this way is rather to use `importlib`.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.or
Hello!
If you want to run a file with its path inside a `my_file` variable, you can
also use `__import__(my_file)`. This will also avoid polluting your namespace,
compared to Cade Brown’s answer.
I have to admit, this is pretty hacky, but I think this is better than a plain
`exec()`. You can
```
import myfile
```
or
```
from myfile import *
```
Will import the names from another file. You should use this instead of
executing text read from a path.
Thanks,
*Cade Brown*
Research Assistant @ ICL (Innovative Computing Laboratory)
Personal Email: brown.c...@gmail.com
ICL/College Em