Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python expand './subfolder' into 'home/username/project/subfolder'

I have a function that takes in a path relative to the current working directory:

get_full_path('./subfolder'):

It should expand the ./ notation into the full root path, returning:

home/username/project/subfolder

Ideally I’d like a single os method that can do this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Here it is in a single os method :

os.path.abspath("./some/relative/path")

Works with or without the ./ in the beginning.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading