Dealing with files...
Alex Martelli
aleax at aleax.it
Sat Apr 26 06:26:15 EDT 2003
George Kinney wrote:
> "lost" <lost at soul.net> wrote in message
> news:pan.2003.04.25.23.29.48.204375 at soul.net...
>> On Fri, 25 Apr 2003 22:51:12 +0000, Alex Martelli wrote:
>> Hi Alex,
>> sorry i wasn't a bit more specific in what i needed, but what you posted
>> was exactly what i was looking for! Thanks a lot.
>>
>
> FWIW, theres also:
>
> from glob import glob
> file_list = glob.glob(SomePath)
> outfile = open(OutputFilename, 'w')
>
> for file in file_list :
> print file
> outfile.write(file + '\n')
>
> outfile.close()
Yes, but - I suggest you AVOID using names of builtin types as names
for your own variables; it's a habit that will eventually "bite" you,
wasting some of your time in the chase for some obscure bug. Just
code the for loop more readably as:
for filename in file_list :
print filename
outfile.write(filename + '\n')
and I think the quality of your code gets substantially enhanced.
Alex
More information about the Python-list
mailing list