小编aza*_*ias的帖子

如何在python中跨脚本共享变量?

以下不起作用

one.py

import shared
shared.value = 'Hello'
raw_input('A cheap way to keep process alive..')
Run Code Online (Sandbox Code Playgroud)

two.py

import shared
print shared.value
Run Code Online (Sandbox Code Playgroud)

在两个命令行上运行:

>>python one.py
>>python two.py
Run Code Online (Sandbox Code Playgroud)

(第二个得到属性错误,这是正确的).

有没有办法实现这一点,即在两个脚本之间共享一个变量?

python variables share

19
推荐指数
6
解决办法
4万
查看次数

标签 统计

python ×1

share ×1

variables ×1