从另一个 python 脚本导入变量需要帮助

Importing variables from another python script help needed

我在同一台计算机上同时有两个 python 脚本 运行。我需要一个脚本从另一个脚本导入变量。我不要导入函数,我要数据,精确到秒。任何帮助将不胜感激。

我建议您从变量中获取数据并将其放入外部文件中,然后以这种方式访问​​信息。

示例:

a.py

import json
    
data = 1
with open(r"examples\data.json", "w") as json_file:
    info = {"Data" : data}
    json.dump(info, json_file)

b.py

import json

with open(r"examples\data.json", "r") as json_file:
    file = json.load(json_file)
    data = file["Data"]

data.json

{"Data": "1"}

希望对您有所帮助!