Run a python script from within a python script

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?

Hi James,

It will be in a pre determined folder so the full path will be know to the python script.

Regards

Roger

https://discourse.mcneel.com/t/listbox-search-bar-for-searching-through-items-in-listbox/89529/5?u=alex43
Maybe this can help.

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

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