Message144141
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:
pass
#
TypeError: open() takes at least 2 arguments (1 given)
The doc for build_opener says it returns an OpenerDirector instance. help(ur.OpenerDirector.open) just says it needs a 'fullurl'. But when I add 'http:www.python.org' 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:33 | terry.reedy | set | recipients:
+ terry.reedy, orsenthil, ezio.melotti, docs@python, Valery.Khamenya |
2011-09-16 17:23:33 | terry.reedy | set | messageid: <1316193813.57.0.779404227637.issue12955@psf.upfronthosting.co.za> |
2011-09-16 17:23:32 | terry.reedy | link | issue12955 messages |
2011-09-16 17:23:32 | terry.reedy | create | |
|