【发布时间】:2022-11-26 02:07:45
【问题描述】:
我的文件名为file1.py,代码如下。
`
import os
global x
def a_function():
while True:
for x in range(12):
cmd=f'rosbag record -O /home/mubashir/catkin_ws/src/germany1_trush/rosbag/{x}.bag /web_cam --duration 5 '
os.system(cmd)
a_function()
I want to acess x in another python scriptfile2.py`代码如下
from file1 import x
print(x)
但问题是当我运行 file2.py 时执行了 file1.py。我只想在 file2.py 中打印 x
无法在另一个 python 脚本中访问全局变量。
【问题讨论】:
标签: python loops module scope global