Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74421 > unrolled thread

Do I need to call close on the handle returned by urlopen?

Started by<krzysztof.zelechowski@syncron.com>
First post2014-07-14 16:59 +0200
Last post2014-07-14 16:20 +0100
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Do I need to call close on the handle returned by urlopen? <krzysztof.zelechowski@syncron.com> - 2014-07-14 16:59 +0200
    Re: Do I need to call close on the handle returned by urlopen? <krzysztof.zelechowski@syncron.com> - 2014-07-14 17:08 +0200
    Re: Do I need to call close on the handle returned by urlopen? Skip Montanaro <skip@pobox.com> - 2014-07-14 10:09 -0500
    Re: Do I need to call close on the handle returned by urlopen? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-14 16:20 +0100

#74421 — Do I need to call close on the handle returned by urlopen?

From<krzysztof.zelechowski@syncron.com>
Date2014-07-14 16:59 +0200
SubjectDo I need to call close on the handle returned by urlopen?
Message-ID<lq0sar$r6e$1@mx1.internetia.pl>
The tutorial says that I should use "with open" to close the file handle
properly.  The reference documentation for urlopen mentions that the handle
returned is like a file handle but the code samples below do not bother to
close the handle at all.  Isn’t it inconsistent? 

[toc] | [next] | [standalone]


#74422

From<krzysztof.zelechowski@syncron.com>
Date2014-07-14 17:08 +0200
Message-ID<lq0sqn$tam$1@mx1.internetia.pl>
In reply to#74421
http://bugs.python.org/issue12955

Użytkownik  napisał w wiadomości grup 
dyskusyjnych:lq0sar$r6e$1@mx1.internetia.pl...

The tutorial says that I should use "with open" to close the file handle
properly.  The reference documentation for urlopen mentions that the handle
returned is like a file handle but the code samples below do not bother to
close the handle at all.  Isn’t it inconsistent? 

[toc] | [prev] | [next] | [standalone]


#74423

FromSkip Montanaro <skip@pobox.com>
Date2014-07-14 10:09 -0500
Message-ID<mailman.11797.1405350590.18130.python-list@python.org>
In reply to#74421
> The tutorial says that I should use "with open" to close the file
> handle properly.  The reference documentation for urlopen mentions
> that the handle returned is like a file handle but the code samples
> below do not bother to close the handle at all.  Isn’t it
> inconsistent?

I think two things might be happening here.

1. Code samples are just that. They often demonstrate usage with the
smallest amount of code possible, so that the key part of what they
are demonstrating isn't lost in a bunch of other clutter. That often
means leaving out error checking and not completely cleaning up after
themselves, especially if those bits might obscure the actual concept
being conveyed.

2. The "with" statement is (relative to many other parts of the
language) still pretty new, so it's not all that surprising that
examples in the documentation haven't all been updated to reflect the
latest recommended practice.

Skip

[toc] | [prev] | [next] | [standalone]


#74425

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-07-14 16:20 +0100
Message-ID<mailman.11799.1405351227.18130.python-list@python.org>
In reply to#74421
On 14/07/2014 15:59, krzysztof.zelechowski@syncron.com wrote:
> The tutorial says that I should use "with open" to close the file handle
> properly.  The reference documentation for urlopen mentions that the handle
> returned is like a file handle but the code samples below do not bother to
> close the handle at all.  Isn’t it inconsistent?

Yes it is.  The latter probably hasn't been updated after the 
introduction of the 'with' keyword and context managers.  Would you like 
to click on the "Report a bug" link on the page in question and suggest 
a change?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web