开发者

Python NameError when using an imported function

When I import开发者_运维问答 and use a function in a python(2.6.5) program, I get an error:

from Localization import MSGR

title = Localization.MSGR("Logfile from Ctf2Rrl.")

NameError: global name 'Localization' is not defined

Could you please explain why?

Regards,


If you import your method like this, you can user MSGR but not Localization.MSGR :)

If you want to use Localization.MSGR, you can just import Localization


The import statement of the form:

from foo import bar

Doesn't introduce the module name (foo) from which the imports (bar) are taken into the module namespace.

Only the name bar is defined, not the module from which you imported `bar.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜