Drive letter mappings in Slicer Python

Is there an easy way to give the Slicer copy of Python access to the network drive letter mappings so that I can use something like os.path.realpath() in my Slicer modules?

Right now my local (non-Slicer) copy of Python 3.8 has no problem converting something like
path = r'B:\folder1
into a full path using
os.path.realpath(path)

But I am unable to reproduce this result in Slicer’s Python Interactor.

Thanks,
Rohan Nadkarni

This is what I get in Slicer:

>>> import os
>>> path=r"m:\tmp"
>>> os.path.realpath(path)
'm:\\tmp'

Do you expect to see something different?

Yes, I am hoping to see the full path.
For example, if m: stands for \networkdrive1, I want the os.path.realpath command to
convert the path into r’\\networkdrive1\tmp’
This is what happens when I use os.path.realpath on my non-Slicer local copy of Python and I would like Slicer Python to have the same access to these drive letter mappings.

Behavior of os.path.realpath on Windows was changed in Python 3.7 or 3.8. To resolve symlinks in a way that is compatible with a wider range of Python versions and operating systems, you can use pathlib:

>>> path = r"m:\tmp"
>>> import pathlib
>>> pathlib.Path(path).resolve()
WindowsPath('//SERVER01/data/tmp')
1 Like