How to get the realpath of a symbolic link?
Wolodja Wentland
wentland at cl.uni-heidelberg.de
Sat Oct 31 18:29:08 EDT 2009
On Sat, Oct 31, 2009 at 14:48 -0500, Peng Yu wrote:
> On Sat, Oct 31, 2009 at 1:46 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> > Peng Yu wrote:
[ snip ]
> I find the following two files that define realpath. But I don't find
> 'realpath' in os.py. I looked at 'os.py'. But I don't understand how
> the function realpath is introduced in the name space in os.path.
> Would you please let me know?
> gfind . ! -path '*backup*' -name "*.py" -type f -exec grep -n "def
> realpath" {} \; -printf %p\\n\\n
> 193:def realpath(path):
> ./macpath.py
>
> 345:def realpath(filename):
> ./posixpath.py
The os module needs to support different platforms. The os.path module
is actually one of the platform specific ones (ntpath, posixpath,
...) that are imported 'as path' depending on the platform the code is
executed.
Have a look at the source code of the os module:
--- os.py - Python 2.6.3 ---
...
f 'posix' in _names:
...
import posixpath as path
elif 'nt' in _names:
...
import ntpath as path
import nt
__all__.extend(_get_exports_list(nt))
del nt
...
else:
raise ImportError, 'no os specific module found'
sys.modules['os.path'] = path
--- snip ---
If you really want to understand how a module is working then have a
look at its source code. Python is open source --> Use that privilige!
kind regards
Wolodja Wentland
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 853 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20091031/1e8030a8/attachment-0001.sig>
More information about the Python-list
mailing list