Python import path containing reserved keyword

Import a module from a path that contains a reserved Python keyword like is. This fixes SyntaxError.

$ python
>>> from import somemodule
File "<stdin>", line 1
    from import somemodule
SyntaxError: invalid syntax

Use importlib to avoid SyntaxError.

$ python
>>> import importlib
>>> mymodule = importlib.import_module('')
>>> mymodule
<module '' from 'some/path/that/contains/is/keyword/mymodule.pyc'>


Leave a Reply