这是one.py:如何在python的其他模块中使用变量?
test = {'1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}
import two
two.example()
这就是two.py:
def example():
print test[1][5]
你能告诉我,为什么这会出现以下错误失败?
NameError: global name 'test' is not defined
谢谢!
'import' Python中没有像在其他语言中'include'。 'import two'创建一个名为'two'的模块对象singleton,其内容由two.py中的代码初始化。它不会将“two.py”的内容复制到解析流中! – 2012-01-13 19:55:19