Mostly Linux & Python syntax notes and hyperlinks.

Friday, March 20, 2015

python: pathlist test with numbered output & avoiding empty values

Here's the code in the previous post with a few enhancements:

import os

def test_path(in_path,sep=';'):
    pl=in_path.split(sep)

    there=[]
    not_there=[]
    for t in pl:
        if len(t) > 1:
            if os.path.isfile(t):
                there.append(t)
            else:
                not_there.append(t)

    print "These exist"
    for i,t in enumerate(there):
        print "%d  %s" % (i+1,t)

    print "\nThese are missing:"

    for i, t in enumerate(not_there):
        print "%d  %s" % (i+1,t)


No comments:

Post a Comment