Pass variable between python scripts

前端 未结 5 1124
北恋
北恋 2020-12-02 18:37

I\'m sure this is very simple but I\'ve been unable to get it working correctly. I need to have my main python script call another python script and pass variables from the

5条回答
  •  不思量自难忘°
    2020-12-02 19:17

    Try use exec Python3.5:

    first.py

    x=5
    exec(open('second.py').read())
    

    second.py

    print(x)
    

    You can also pass x by using:

    x=5
    myVars = {'x':x}
    exec(open('second.py').read(), myVars)
    

    Not sure if this is a good way.

提交回复
热议问题