Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #47790 > unrolled thread

Re: ValueError: I/O operation on closed file. with python3

Started byAdam Mercer <ramercer@gmail.com>
First post2013-06-12 07:15 -0500
Last post2013-06-12 07:15 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: ValueError: I/O operation on closed file. with python3 Adam Mercer <ramercer@gmail.com> - 2013-06-12 07:15 -0500

#47790 — Re: ValueError: I/O operation on closed file. with python3

FromAdam Mercer <ramercer@gmail.com>
Date2013-06-12 07:15 -0500
SubjectRe: ValueError: I/O operation on closed file. with python3
Message-ID<mailman.3065.1371039350.3114.python-list@python.org>
On Wed, Jun 12, 2013 at 2:26 AM, Peter Otten <__peter__@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):
>       yield urlopen(url).fp
>
> except ImportError:
>   # python-3.x
>   from urllib.request import urlopen
>   from configparser import ConfigParser
>   import io
>
>   @contextmanager
>   def my_urlopen(url):
>       resp = urlopen(url)
>       yield io.TextIOWrapper(resp.fp)
>
> server='http://www.lsc-group.phys.uwm.edu/~ram/files'
>
> cp = ConfigParser()
> with my_urlopen('%s/latest.ini' % server) as fp:
>     cp.readfp(fp)
>
> print(cp.get('version', '10.8'))
>
> I've run it with 2.6, 2.7, 3.2, and 3.3.

Thanks that's very helpful, I hadn't realised that .readfp() had been
deprecated.

Cheers

Adam

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web