absolute path to a file

Cameron Simpson cs at cskk.id.au
Thu Aug 15 19:00:38 EDT 2019


On 15Aug2019 22:52, Manfred Lotz <ml_news at posteo.de> wrote:
>On Thu, 15 Aug 2019 22:00:17 +0200
>Paul St George <email at paulstgeorge.com> wrote:
>> But I want an absolute path such as:
>> ---Plane uses image01.tif saved
>> at /Users/Lion/Desktop/test8/image01.tif ---Plane uses image02.tif
>> saved at /Users/Lion/Desktop/images/image02.tif
>>
>> If it is relevant, my files are on a Mac. Hence the escaped forward
>> slash.

You don't need to double the leading slash on a Mac.

On 15Aug2019 22:52, Manfred Lotz <ml_news at posteo.de> wrote:
>I did this:
>from pathlib import Path
>abs_myfile = Path('./myfile').resolve()
>which worked fine for me.

There is also os.path.realpath(filename) for this purpose. In modern 
Python that also accepts a Pathlike object.

Cheers,
Cameron Simpson <cs at cskk.id.au>



More information about the Python-list mailing list