absolute path to a file
On 20Aug2019 21:06, Paul St George <email at paulstgeorge.com> wrote:
>On 20/08/2019 11:43, Cameron Simpson wrote:
>>Please remember to CC the list.
>Instead of 'Post a followup to this newsgroup' or 'To:
>python-list at python.org'?
Hmm. I've been getting some of your posts directly to me as email with
no obvious python-list at python.org to/cc header. Maybe some interaction
with gmane? If you've been posting to the gmane newsgroup and CCing me
privately that is likely fine, and I've misread the event (provided
gmane backfeeds to the mailing list).
>blend_file = '/Users/Lion/Desktop/test8/tifftest8.blend'
>So, if I read you correctly, this is an absolute path.
>When we used unblenderise on it, out popped a path that was partly but
>not wholly relative. The latter half of the path is relative to the
>absolute first half (/Users/Lion/Desktop/test8/).
>It starts with a slash but cannot be pasted into "Go to...". But maybe
>that is an absolute path in UNIX?
Yes. It starts with a slash.
If you hand this to abspath it would fold out the "test8/.." part and
give you a more direct absolute path.
And realpath would traverse the path looking for symlinks etc and fold
out the same pair as a side effect of traversing the path.
But realpath is symlink aware. If test8 were a symlink to some remote
part of the filesystem so that the TIF image were also elswhere, you'd
get a direct path to that remote location.
For example, on our home server my ~/media directory is actually a
symlink to an area on our 8TB RAID-1 volume:
[~]borg*> ls -ld media
lrwxrwxrwx 1 cameron cameron 9 Nov 2 2017 media -> 8TB/media
In fact "8TB" is also a symlink. So let's look:
Python 3.7.1 (default, Nov 14 2018, 10:38:43)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from os.path import abspath, realpath
Both are valid absolute paths to the media directory.
Realpath has follwed the symlinks and given a direct route from '/'
which does not go through any symlinks. Abspath has not bothered with
Cameron Simpson <cs at cskk.id.au> (formerly cs at zip.com.au)