[Python-Dev] Fwd: Re: Add os.path.resolve to simplify the use of os.readlink

Calvin Spealman ironfroggy at gmail.com
Thu Jun 21 13:34:58 CEST 2012


---------- Forwarded message ---------- (whoops from my phone)

On Jun 21, 2012 6:32 AM, "Armin Ronacher" <armin.ronacher at active-4.com>
wrote:
>
> Due to an user error on my part I was not using os.readlink correctly.
> Since links can be relative to their location I think it would make sense
> to provide an os.path.resolve helper that automatically returns the
> absolute path:
>
>    def resolve(filename):
>        try:
>            target = os.readlink(filename)
>        except OSError as e:
>            if e.errno == errno.EINVAL:
>                return abspath(filename)
>            raise
>        return normpath(join(dirname(filename), target))
>
> The above implementation also does not fail if an entity exists but is not
> a link and just returns the absolute path of the given filename in that
> case.
>

Does it need to be an absolute path, and what if the advantage of that? Can
it returned absolute if that's what you gave it, and relative otherwise?

>
> Regards,
> Armin
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
http://mail.python.org/mailman/options/python-dev/ironfroggy%40gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120621/f95b35ac/attachment.html>


More information about the Python-Dev mailing list