12.06.13 10:26, Peter Otten написав(ла):
@contextmanager
def my_urlopen(url):
resp = urlopen(url)
yield io.TextIOWrapper(resp.fp)
with urlopen(url) as resp:
yield io.TextIOWrapper(resp)
Note that last bugfix releases (i.e. 3.3.1) are needed. There was a
On Wed, Jun 12, 2013 at 2:26 AM, Peter Otten <__pete...@web.de> wrote:
> Applying these findings to your script:
>
> from contextlib import contextmanager
> try:
> # python-2.x
> from urllib2 import urlopen
> from ConfigParser import ConfigParser
>
> @contextmanager
> def my_urlopen(url)
Adam Mercer wrote:
> Hi
>
> I'm trying to update one of my scripts so that it runs under python2
> and python3, but I'm running into an issue that the following example
> illustrates:
>
> $ cat test.py
> try:
> # python-2.x
> from urllib2 import urlopen
> from ConfigParser import ConfigPar
Hi
I'm trying to update one of my scripts so that it runs under python2
and python3, but I'm running into an issue that the following example
illustrates:
$ cat test.py
try:
# python-2.x
from urllib2 import urlopen
from ConfigParser import ConfigParser
except ImportError:
# python-3.x
f