Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

function - Calling external python script in main script and run there

Objective:

when fun() is run it should insert the script of external.py in main_script.py and run like a single file.

main_script.py

def fun():
    x1 = 60
    x2=80
    exec(open('second.py').read())
    return(z1,z2)

print(fun()) # should print value to z1 and z2;

external_script.py

z1=x1+x2
z2=x1-x2
question from:https://stackoverflow.com/questions/65839326/calling-external-python-script-in-main-script-and-run-there

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...