How to get the realpath of a symbolic link?

Emile van Sebille emile at fenx.com
Sat Oct 31 12:26:44 EDT 2009


On 10/31/2009 12:03 AM Peng Yu said...
> Suppose that I have the following directory and files. I want to get
> the canonical path of a file, a directory or a symbolic link.
> For example, for 'b' below, I want to get its canonical path as
> '/private/tmp/abspath/b'.

So, why isn't realpath working for you?  It looks like it is, and it 
works that way here:

 >>> os.path.realpath('/home/emile/vmlinuz')
'/root/vmlinuz-2.4.7-10'


Emile




More information about the Python-list mailing list