Open a List of Files

BJ Swope bigblueswope at gmail.com
Mon Jan 7 21:04:27 EST 2008


given a list such as

['messages', 'recipients', 'viruses']

how would I iterate over the list and use the values as variables and open
the variable names a files?

I tried

for outfile in ['messages', 'recipients', 'viruses']:
    filename = os.path.join(Host_Path, outfile)
    outfile = open(filename, 'w')


But it's not working.



-- 
We are all slave to our own paradigm. -- Joshua Williams

If the letters PhD appear after a person's name, that person will remain
outdoors even after it's started raining. -- Jeff Kay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080107/5947ff26/attachment.html>


More information about the Python-list mailing list