[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Open a List of Files

Martin Marcher

1/8/2008 12:04:00 PM

BJ Swope wrote:

> On Jan 8, 2008 6:03 AM, Fredrik Lundh <fredrik@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')

files = dict()
l = ['messages', 'recipients', 'viruses']
for f in l:
files[f] = open(s.path.join(Host_Path, outfile), "w")

files["messages].write("a string")

hth
martin

PS: Code is untested

--
http://noneisyours.ma...
http://feeds.feedburner.com/N...

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.