Open a List of Files

BJ Swope bigblueswope at gmail.com
Tue Jan 8 06:54:32 EST 2008


On Jan 8, 2008 6:03 AM, Fredrik Lundh <fredrik at pythonware.com> wrote:

> BJ Swope wrote:
>
> > 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.
>
> the code looks ok.  please define "not working".
>
> </F>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Yep, defining "not working" is always helpful! :)

I want to have all 3 files open at the same time.  I will write to each of
the files later in my script but just the last file is open for writing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080108/a8f3e67b/attachment.html>


More information about the Python-list mailing list