[Python-ideas] Re: A python_include() for cgi programming

2020-11-26 Thread Voltron via Python-ideas
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

[Python-ideas] Re: A python_include() for cgi programming

2020-11-04 Thread Mathew Elman
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

[Python-ideas] Re: A python_include() for cgi programming

2020-11-04 Thread Matteo Bertucci
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

[Python-ideas] Re: A python_include() for cgi programming

2020-11-03 Thread Cade Brown
``` 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