I'm working on the pythonizer, a program to translate perl to python, and I'm looking to translate the statement "require FILENAME;" to python. In this case I need to generate "from FILENAME import *". I figured out the "from FILENAME" part (here BASENAME is the FILENAME without the path or extension):
from importlib.machinery import SourceFileLoader
module = SourceFileLoader(BASENAME, FILENAME).load_module()
and the import * part is coded as:
__import__(name, fromlist=['*'])
but how do I combine them?
I see _handle_fromlist in importlib._bootstrap, but calling an internal routine is most likely not the right answer here.