current_code = dsajJasndfD
is in second file also. I need to import it by using local current_code (it will be changing after every program restart).
So here is my question: How can I import module, when I don't know its, but have it name assigned as local variable?
current_code = dsajJasndfD
import database as db
key_list = list(db.current_code.keys())
value_list = list(db.current_code.values())
martineau
124k29 gold badges180 silver badges317 bronze badges
1 Answer 1
This should do the trick:
current_code = "foo.py"
__import__(current_code)
answered Jan 17, 2020 at 23:07
lang-py
dsajJasndfD
be string? Do i get it ok, that it's the name of the other file - the package to be imported?dsajJasndfD
?importlib
is the module you are looking for docs.python.org/3/library/…