Walking The Right Path

Tim Daneliuk tundra at tundraware.com
Mon Jan 8 17:29:05 CET 2007


Jakub Stolarski wrote:
> Tim Daneliuk napisal(a):
>> Ah yes, moral philosophy and python all come together... Er, that is to day:
>>
>> Imagine you have this situation on a *nix filesystem:
>>
>> Symlink A:  /foo -> /usr/home
>> Symlink B:  /bar -> /foo/username
>>
>>
>> If I do this:
>>
>>    import os
>>    print os.path.realpath("/bar")
>>
>> I get this (as one would expect):
>>
>>    /usr/home/username
>>
>> However, what if I want to get back the result in this form:
>>
>>    /foo/username
>>
>>
>> IOW, is there a way to return a symlink-based path which contains
>> the symlink pointer as is was *defined* not as it expands?
>>
> 
> One way (but very ugly):
> print os.path._resolve_link('/bar')
> 

Yup, that does just what I want.  By why, pray tell, do you consider it
ugly ...?


-- 
----------------------------------------------------------------------------
Tim Daneliuk     tundra at tundraware.com
PGP Key:         http://www.tundraware.com/PGP/



More information about the Python-list mailing list