0
我有功能:爲什麼我得到的消息:「模塊」對象有沒有屬性「load_source」
def load_from_file(filepath, expected_class):
mod_name, file_ext = os.path.splitext(os.path.split(filepath)[-1])
py_mod = imp.load_source(mod_name, filepath)
在templatetags文件
,它是確定的。
但是,當我複製/粘貼此功能,我認爲我得到錯誤:
'module' object has no attribute 'load_source'
我的例子觀點:
import os, imp
def get_module(request, position):
[...]
imod = load_from_file(settings.PROJECT_ROOT + '/core/manager/modules/' + mod.type.fileview + '.py', 'ModuleManager')
[...]
def load_from_file(filepath, expected_class):
[...]
爲什麼這不工作?
在兩個模塊中打印imp(在調用函數之前)並查看是否有不同的東西 –
是的,我有我自己的模塊名爲imp – Nips