Python import path containing reserved keyword

Import a module from a path containing a reserved keyword like "is".

This import statement fails because the word "is" is a reserved in python.

from foo.com.example.is.path.somewhere.api.v1 import resources

Use importlib to import.

import importlib
 
mymodule = importlib.import_module('foo.com.example.is.path.somewhere.api.v1.resources')
Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment