问题描述
我的项目有一个巨大的副作用:
在我的项目中我需要写gobal使用全球符号:
....
导入数学
....
def f():
全球数学#必要??????否则下一行会产生错误
留言?????
打印math.pi
(问题适用于所有人全局模块符号)
我的项目肯定会改变,但我找不到什么?
(只是一个小的)当然没有这种全球性的程序麦芽汁很好)
任何人都可以帮助我:我在哪里可以搜索项目中的错误?
I have a stange side effect in my project :
in my project I need to write "gobal" to use global symbol :
....
import math
....
def f() :
global math # necessary ?????? else next line generate an error
message ?????
print math.pi
(the problem is for all global module symbol)
I have certainly change somthing in my project, but I can''t find what ?
(just a small program wort fine without this global of course)
Can anybody help me : where can I search the mistake in my project ?
推荐答案
你只需要全局如果你在某个地方指定名称
稍后在函数中(例如math = ...或import math或其他一些
赋值)
请发布错误信息(整个追溯)。
< / F>
you only need global in this case if you assign to the name somewhere
later in the function (e.g. "math = ..." or "import math" or some other
assignment)
please post the error message (the entire traceback).
</F>
这篇关于为什么我需要将导入声明为全局函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!