[Tutor] Dynamically assign variable names to tuple objects

Sean Carolan scarolan at gmail.com
Tue Mar 1 18:55:12 CET 2011


Maybe someone can help with this.  I have a function that takes a
single file as an argument and outputs a tuple with each line of the
file as a string element.  This is part of a script that is intended
to concatenate lines in files, and output them to a different file.
This is as far as I've gotten:

<code>
import sys

myfiles = tuple(sys.argv[1:])
numfiles = len(myfiles)

def makeTuple(file):
    outlist = []
    f = open(file, 'r')
    for line in f.readlines():
        line = line.rstrip(' \n')
        outlist.append(line)
    return tuple(outlist)

for i in range(numfiles):
    makeTuple(myfiles[i])
</code>

The script creates the tuples as it was intended to, but I'm not sure
how to assign variable names to each tuple so that I can work with
them afterwards.  How would you dynamically assign variable names to
each tuple created by makeTuple(), so that they can be manipulated
further?


More information about the Tutor mailing list