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.
Would:
path.split('.py')[0].replace("/", ".")
be suitable?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With