Prev: globbal | creating networks
Next: Beyond the moratorium
From: John Nagle on 12 Aug 2010 01:34 Somewhat to my surprise, in Python 2.6, with urllib2.urlopen(url) as fh : doesn't work. It fails with "AttributeError: addinfourl instance has no attribute '__exit__'". I thought that all the file-like objects supported "with" in 2.6. No? John Nagle
From: Paul Rubin on 12 Aug 2010 02:14 John Nagle <nagle(a)animats.com> writes: > "AttributeError: addinfourl instance has no attribute '__exit__'". > > I thought that all the file-like objects supported "with" in 2.6. > No? I guess not. Use contextlib.closing.
From: Terry Reedy on 12 Aug 2010 15:10 On 8/12/2010 1:34 AM, John Nagle wrote: > Somewhat to my surprise, in Python 2.6, > > with urllib2.urlopen(url) as fh : > > doesn't work. It fails with > "AttributeError: addinfourl instance has no attribute '__exit__'". > > I thought that all the file-like objects supported "with" in 2.6. > No? This seems to work in 3.1, which first came out almost a year after 2.6. from urllib.request import urlopen with urlopen("http://www.python.org") as fh : pass -- Terry Jan Reedy
|
Pages: 1 Prev: globbal | creating networks Next: Beyond the moratorium |