Python NameError when using an imported function

。_饼干妹妹 提交于 2021-02-05 11:50:56

问题


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,


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/7083496/python-nameerror-when-using-an-imported-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!