Reputation: 51
I would like to convertos file paths like './foo/bar/file.py'
to paths used in python import like 'foo.bar.file'
.
I could very easily code my self these functions, but I wanted to know if there is a function for making that?
It would be great also if the functions works for windows and linux file paths
Upvotes: 0
Views: 50
Reputation: 2098
try this:
import pathlib
path = pathlib.Path('foo/bar/file.py')
formatted_path = '.'.join(path.with_suffix('').parts)
# And do what you want with formatted_path
Upvotes: 2