file.close()

Bryan belred1 at yahoo.com
Thu Jul 24 02:13:43 EDT 2003


"Ben Finney" <bignose-hates-spam at and-benfinney-does-too.id.au> wrote in
message news:slrnbhusl6.13c.bignose-hates-spam at iris.polar.local...
> On Thu, 24 Jul 2003 05:20:15 GMT, Bryan wrote:
> >>     filelist = []
> >>     try:
> >>         filelist.append(open(filename[0]))
> >>         filelist.append(open(filename[1]))
> >>         ...
> >>         do_something(filelist)
> >>     finally:
> >>         for f in filelist:
> >>             f.close()
> >
> > erik, carl... thanks... this is exactly what i was looking for
>
> The only substantial difference I see between this and what you
> originally posted, is that there is only one 'try...finally' block for
> all the file open/close operations.  Is this what you were wanting
> clarified?
>

well, it wasn't exactly clarification as much as seeing another more
scalable solution.  i know a lot of people don't explicitly close files in
python, but i always do even for small scripts.

thanks again,

bryan






More information about the Python-list mailing list