Python os module path functions
Posted
by
broiyan
on Stack Overflow
See other posts from Stack Overflow
or by broiyan
Published on 2011-01-07T05:28:23Z
Indexed on
2011/01/07
5:54 UTC
Read the original article
Hit count: 297
From the documentation:
os.path.realpath(path)
Return the canonical path of the specified filename, eliminating any
symbolic links encountered in the path (if they are supported by the
operating system).
When I invoke this with an extant file's name, I get the path to it: /home/myhome/myproject
.
When I invoke this with a 'nonsense.xxx' string argument, I still get a path to /home/myhome/myproject/nonsense.xxx
. This is a little inconsistent because it looks like nonsense.xxx
is taken to be a directory not a file (though it is neither: it does not exist).
When I invoke this with a null string file name, I still get a path to /home/myhome/myproject
.
How can I account for this behaviour when the documentation says so little about realpath()? (I am using Python 2.5.)
Edit: Somebody suggested a way to test if files exist. My concern is not to test if files exist. My concern is to account for behaviour.
© Stack Overflow or respective owner