Message144141
| Author |
terry.reedy |
| Recipients |
Valery.Khamenya, docs@python, ezio.melotti, orsenthil, terry.reedy |
| Date |
2011年09月16日.17:23:32 |
| SpamBayes Score |
4.8268365e-08 |
| Marked as misclassified |
No |
| Message-id |
<1316193813.57.0.779404227637.issue12955@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|