How to pass a list of arguments to a function so that it performs it in order (not simultaneously on all elements of the list) in python?

Viewed 52

This is a function that counts numbers on a txt. First, it navigates through directories. For that, I have to use os.path.join.

def checkmove(subject):
    os.chdir(os.path.join(directory, subject, 'func', 'run 1'))
    print("Check for volumes repaired in " + subject+ ":")
    try:
        f = open('art_repaired.txt', 'r')
    except:
        print("'art_repaired.txt' not found")
    tot_vols = 0
    for line in f:
        parts = line.split()
        tot_vols += len(parts)       
    print("Volumes repaired in run 1: "+ str(tot_vols))
    del f, tot_vols, parts

The problem is I would need to pass a list of arguments (subjects) to the function, so that the function is performed on each element of the list in order, one by one.

Of course, if I try, it gives me the error:

TypeError: join() argument must be str, bytes, or os.PathLike object, not 'list'

How could I do this??

1 Answers
def checkmove(*subject):
    for foobar in subject:
        os.chdir(os.path.join(directory, subject, 'func', 'run 1'))
        whatyouwanthere
Related