【发布时间】:2012-04-28 16:54:11
【问题描述】:
from os import listdir
modo= [name.split(".py")[0] for name in listdir("scripts") if name.endswith(".py")]
modules = {}
for modu in modo:
modules[modu] = __import__(modu)
test_samp.function("test")
你好! 如果说脚本目录中存在“test_samp.py”,为什么 这不允许我运行 test_samp.function("test")? 它返回:
Unhandled exception in thread started by <function function at 0x8e39204>
Traceback (most recent call last):
File "test_this.py", line 6, in function
test_samp.function("test")
NameError: global name 'test_samp' is not defined
【问题讨论】:
-
你有
__init__.py文件吗? -
是的,但不管有没有,都没有区别。 ://
标签: python import module directory