How to User Variable Names For Opening One or More Files In Python?
<p>Python newb and first-time poster...</p>

<p>I'm building a mass disk copying program and have been pretty successful in working through issues until now. I am trying to open from 1 to n (up to 28) files (actually drives in Linux, e.g., /dev/sdc, /dev/sdd, ...), depending on user checkbox selection. </p>

<p>I'm using something like below, but of course am getting a "can't assign to function call" error when the code hits the eval line. This is not the actual code, but replicates my problem; please ignore the file paths.</p>

<p>What is an appropriate way to do this? </p>

<pre><code>#!/usr/bin/env python

class snippet:
    def __init__(self):
        # open files for binary writing
        file_in = open('/dev/null', 'rb')
        ints = [0, 1, 2, 3]
        for i in ints:
            num = str(i)
                eval('f_out' + num) = open('/tmp/tmp' + num, 'wb') 

        # READ/WRITE CODE GOES HERE 

        # close files
        file_in.close()
        for i in ints:
            num = str(i)
            print "Number: " + num
            eval("f_out" + num).close() 

if __name__ == '__main__':
    app = snippet()
</code></pre>

<p>Thanks,
   Roy</p>
