2017-11-02 12 views
0

, 나는이 : vmtk 가져 오기 vmtkscripts라는 이름의 모듈 'vmtkactivetubes'내 파이썬 코드에서

프로그램에서

는 "vmtkscripts.py"를 찾는데 문제가 없습니다. 그러나, vmtkscripts.py에서 나는 vmtkactivetubes.py가 vmtkscripts.py "와 같은 폴더에" "

__all__ = ['vmtkactivetubes']

for item in __all__: 
    exec('from '+item+' import *') 

"ModuleNotFoundError "를 실행 한 후.

내가 얻을"이 : 'vmtkactivetubes'라는 모듈이 없습니다. " 그러나이"vmtk import vmtkactivetubes에서 "는 오류를주지 않습니다.

도와 주시면 감사하겠습니다. 반란군?

답변

0

이 범위의 문제,

는 사용해보십시오 :

exec('from '+item+' import *', globals()) 

이를 documentation에서 : 귀하의 코멘트에 대한

In all cases, if the optional parts are omitted, the code is executed in the current scope. If only globals is provided, it must be a dictionary, which will be used for both the global and the local variables. If globals and locals are given, they are used for the global and local variables, respectively. If provided, locals can be any mapping object. Remember that at module level, globals and locals are the same dictionary. If exec gets two separate objects as globals and locals, the code will be executed as if it were embedded in a class definition.

+0

감사합니다. 그러나, 나는 여전히 같은 오류가 발생합니다! :( –