RogerD
1
Hi all,
I have a python 3 script and wish to run another python 3 script based on data selected in the first script and saved as global variables.
Is there an easy way to do this ? just cannot find anything obvious in the script editor files.
Roger
Where is the other Python 3 script? Can you install it as a library, or add its parent dir to sys.path, and just import it?
RogerD
3
Hi James,
It will be in a pre determined folder so the full path will be know to the python script.
Regards
Roger
Alex43
(Alex)
4
RogerD
5
Hi Alex,
Thanks but I think I have resolved my issue by the following code.
# Main script
script_path = "C:\V8 Scripts CL Nov 24\Test1.py3"
with open(script_path, 'r') as file:
script_content = file.read()
exec(script_content)
It was the exec command that I could not find but this solves my problem.
Roger
Tom_P
6
use import
see
https://csatlas.com/python-import-file-module/
or other tutorials.
for other approaches see stackoverflow
googleo or read why import is used instead of exec
cheers -tom