Author terry.reedy
Recipients Valery.Khamenya, docs@python, ezio.melotti, orsenthil, terry.reedy
Date 2011-09-16.17:23:32
SpamBayes Score 4.82684e-08
Marked as misclassified No
Message-id <>
As I understand this, you are asking that 2.7 urllib2.build_opener().open(), which in 3.x is urllib.request.build_opener().open(), be upgraded to return an object that works as a context manager. Unless the docs say that this should already be the case, this is a feature request for 3.3.

I am unable to test whether this feature is already present (in 3.2.2). Your example line "with urllib2.build_opener().open() as:" has an obvious syntax error. When I correct that and adjust for 3.x

import urllib.request as ur
with ur.build_opener().open() as f:
TypeError: open() takes at least 2 arguments (1 given)

The doc for build_opener says it returns an OpenerDirector instance. help( just says it needs a 'fullurl'. But when I add '' as an argument, I get
urllib.error.URLError: <urlopen error no host given>
I do not know what else is needed.

Please copy and paste the ACTUAL (minimal) code you ran to get the AttributeError.
Date User Action Args
2011-09-16 17:23:33terry.reedysetrecipients: + terry.reedy, orsenthil, ezio.melotti, docs@python, Valery.Khamenya
2011-09-16 17:23:33terry.reedysetmessageid: <>
2011-09-16 17:23:32terry.reedylinkissue12955 messages
2011-09-16 17:23:32terry.reedycreate