nntplib, huge xover object

Robin Munn rmunn at pobox.com
Mon Apr 7 16:45:21 EDT 2003


Mike Meyer <mwm at mired.org> wrote:
> Robin Munn <rmunn at pobox.com> writes:
>>     xover(start, end, open('foo.txt', 'w'))
>> 
>> See? File-like object gets created, passed to your function, and then
>> automatically garbage-collected (and thus closed) when your function
>> returns.
> 
> The garbage collection happening when your function returns is
> implementation specific. It works that way in CPython, but not
> Jython. You should always explicitly close files to make sure they get
> closed - and the output flushed, in this case - when you're done with
> them.

Good point, thanks. Ignore what I said above; what you should do is:

    output_file = open('foo.txt', 'w')
    xover(start, end, output_file)
    output_file.close()

-- 
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838    50FF 2478 CFFB 081A 8338  54F7 845D ACFD 6AFB 6838




More information about the Python-list mailing list