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

Alan Gauld alan.gauld at yahoo.co.uk
Sun Jan 7 19:39:07 EST 2018


On 08/01/18 00:17, boB Stepp wrote:

>> The os.path module is mostly a string manipulation toolkit.
> 
> This is the critical piece that was eluding me.  I assumed that the
> actual file system was being queried, checked and expanded as needed.

To be fair realpath() does do a tiny bit of magic in that it
checks if the file (or any part of the path) is a link (aka
shortcut) and tries to give you the actual path to the
original file - ie it follows the link. I'm not sure how
effective it is, I've only played with it but never used
it in earnest.

But in general I tend not to rely on os.path doing anything
remotely clever.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list