[Tutor] Why does os.path.realpath('test_main.py') give different results for unittest than for testing statement in interpreter?

boB Stepp robertvstepp at gmail.com
Sun Jan 7 17:56:52 EST 2018


On Sun, Jan 7, 2018 at 4:51 AM, Albert-Jan Roskam
<sjeik_appie at hotmail.com> wrote:
>
> On Jan 7, 2018 09:08, Steven D'Aprano <steve at pearwood.info> wrote:

>> realpath() returns the canonical path of the given filename. It doesn't
>> try to locate some actual existing file.
>
> I always thought that os.path.realpath is the Python equivalent of Linux realpath/readlink (http://man7.org/linux/man-pages/man3/realpath.3.html). And that, thus, there's only a difference between input and output when the input is a symlink (and maybe also when it's a hard link - in this case the function actually also does something in Windows). But then, I don't really know the meaning of the word "canonical", to tell you the truth (maybe #4 in http://www.dictionary.com/browse/canonical)

My hangup was mostly that I was assuming that an actually existing
path to a real file was implied.  Apparently that is not the case.  So
Alan's explanation has cleared that up for me (I think!).

I agree with you that the 4th definition you cite:

"4. Mathematics. (of an equation, coordinate, etc.) in simplest or
standard form."

is the most sensible definition in this context with Steve's caveats.

-- 
boB


More information about the Tutor mailing list