On 18/08/2019 02:03, Cameron Simpson wrote:
On 17Aug2019 11:51, Paul St George <em...@paulstgeorge.com> wrote:
print('Track D  from Track B:',os.path.realpath(n.image.filepath))
---Track D  from Track B: /image01.tif

print('Track E  from Track B:',os.path.realpath(n.image.filepath[1:]))
---Track E  from Track B: /image01.tif

print('Track F from Track C:',os.path.realpath(n.image.filepath[2:]))
---Track F from Track C: /image01.tif

I know these may just be cut/paste, but you can shorten this by:

    from os.path import realpath
    print('Track F from Track C:',realpath(n.image.filepath[2:]))

I have 2 other questions:

1: Is image01.tif a real existing file when you ran this code?

realpath kind of expects that - it may do nothing for something which doesn't exist. I'd point out that realpath(3), which you get from the command "man 3 realpath", says:

   The realpath() function will resolve both absolute and relative paths and
    return the absolute pathname corresponding to file_name.  All
    components of file_name must exist when realpath() is called.

Most of the things in the os module are just thin wrappers for the OS supplied functions, which is why the MacOS realpath library function is relevant.

2: What is your current working directory when you run this code?

If the underlying OS realpath fails, the Python library function might fall back on os.path.join(os.getcwd(), filename).

3: What is the airspeed velocity of an unladen swallow?

https://www.python.org/dev/peps/pep-0234/#rationale

Cheers,
Cameron Simpson <c...@cskk.id.au> (formerly c...@zip.com.au)

1:
Is image01.tif a real existing file when you ran this code?

Yes. image01.tif is real, existing and apparent.

>>> print(obj.name,'uses',n.image.name,'saved at',n.image.filepath, 'which is at', realpath(n.image.filepath))
gives:
Plane uses image01.tif saved at //image01.tif which is at /image01.tif

(Chris and Peter lead me to believe that Blender has a special kind of relative path. The double slashes replace the path to the blend file’s directory.) realpath has done something but I know not what.


2a:
What is your current working directory when you run this code?

Well, there at least two answers to that question. Within Blender's Python Console:
>>> os.getcwd()
‘/‘

But I am *guessing* the real location of the CWD is
/Applications/Blender/blender.app/Contents/Resources/2.79/scripts

I tried using realpath, bpy.path.abspath, and os.path.abspath on this forward slash but nothing changed.

For amusement, I also tried print(os.path.join(os.getcwd(), os.getcwd()))

2b:
If the underlying OS realpath fails, the Python library function might fall back on os.path.join(os.getcwd(), filename).

It should, shouldn’t it. But it doesn’t. Anyway, wouldn’t this be an absolute path via the location of the CWD?


3: What is the airspeed velocity of an unladen swallow?
Do you know the speed and direction of the swallow?



--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to