Real path of file string pathlib

Viewed 4925

I've been searching for what seems like hours for how to get a real path in string format from a pathlib.PosixPath using pathlib.

The only solution I can find is this:

str(myPathObject.resolve())

This seems messy. Am I missing something or is this only solution that exists?

Edit:

To clarify, this is giving me a filepath /opt/digglerz/projects of type string, which is what i want. This seems a long way to do this, is there no better way?

2 Answers

resolve() is a good idea, but the literal casting with str indeed seems a bit messy. I would go with built-in methods like as_posix() or as_uri() depending on what you want.

Understand that the concept of "real path" as you call it may be different in different situations and on different platforms.

Hope this helps!

Related