2017-11-02 12 views
0

は、私が持っている:vmtkインポートvmtkscriptsという名前のモジュールのvmtkactivetubes「私のPythonコードで

プログラムから

は "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

あなたのコメントをありがとう。しかし、私はまだ同じエラーが表示されます! :( –

関連する問題