Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ランダムインポートを行うにはどうすればよいですか? 例えば:
1 つまたは別のファイルをインポートする 2 の確率
import file1 OR import file2
アプローチは、を使用することimportlib.import_moduleです。
importlib.import_module
from random import choice from importlib import import_module sources = [ 'file1', 'file2', ] source = import_module(choice(sources))
モジュールは から利用できるようになりますsource。
source