tests/readlink.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Mon, 12 Oct 2015 00:45:24 -0700
changeset 26603 517ffec37dee
parent 25660 328739ea70c3
child 29175 7bcfb9090c86
permissions -rwxr-xr-x
discovery: put trivial branch first Having the simple and tiny branch of the conditional first help readability. The "else" that appears after a screen of code is harder to relate to a conditional.

#!/usr/bin/env python

import errno, os, sys

for f in sys.argv[1:]:
    try:
        print f, '->', os.readlink(f)
    except OSError as err:
        if err.errno != errno.EINVAL:
            raise
        print f, 'not a symlink'

sys.exit(0)