开发者

Why do I get the message: 'module' object has no attribute 'load_source'

I have function:

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)

in templatetags file and it is ok.

But when i copy/paste this function to my view i get error:

'module' object has no attribute 'load_source'

My example view:

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):
    [...]
开发者_运维百科

Why this not working?


You have another module named imp.

Either rename it, move it either to a spot later in your sys.path than the standard library modules or out of sys.path completely, or rearrange your sys.path.

It's most likely in the same directory as your views; if that's the case, the easiest thing to do is probably to move it to a directory where no modules import imp or rename it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜