Reputation: 3071
Is there a built-in or simple way to convert a file path (module path) to a name
argument to be used by the importlib.import_module function?
For example:
'path/module.py' -> 'path.module'
I could do something like this:
if path.endswith('.py'):
path = path[:-3]
path = path.replace('/', '.')
But I was looking for a simpler way.
Upvotes: 3
Views: 644