小编Sea*_*Cav的帖子

全局变量和模块(简单示例帮助)Python

好吧我正在做一些线程,我想当我开始做线程时我假设你不能返回像定义这样的值(它的结束时间和我的大脑即将死亡所以这可能是不正确的我应该开始去回去摆脱全局变量)

无论如何,我有一个测试程序来弄清楚为什么我不能模块化我的代码

一个名为config.py的文件

a_variable=0
Run Code Online (Sandbox Code Playgroud)

一个名为test_for_sean.py的文件

from config import *
def blah():
  global a_variable
  a_variable=14
  return 0
Run Code Online (Sandbox Code Playgroud)

一个名为main.py的文件

from config import *
from test_for_sean import *
print a_variable #this prints correctly
blah()
print a_variable #this is still printing 0....
Run Code Online (Sandbox Code Playgroud)

有人把我联系起来,所以我不会自杀

python import module global-variables

2
推荐指数
1
解决办法
1839
查看次数

标签 统计

global-variables ×1

import ×1

module ×1

python ×1