0

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

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.