Quantcast
Channel: Reopening a closed stringIO object in Python 3 - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Reopening a closed stringIO object in Python 3

$
0
0

So, I create a StringIO object to treat my string as a file:

>>> a = 'Me, you and them\n'>>> import io>>> f = io.StringIO(a)>>> f.read(1)'M'

And then I proceed to close the 'file':

>>> f.close()>>> f.closedTrue

Now, when I try to open the 'file' again, Python does not permit me to do so:

>>> p = open(f)Traceback (most recent call last):  File "<pyshell#166>", line 1, in <module>    p = open(f)TypeError: invalid file: <_io.StringIO object at 0x0325D4E0>

Is there a way to 'reopen' a closed StringIO object? Or should it be declared again using the io.StringIO() method?

Thanks!


Viewing all articles
Browse latest Browse all 5

Trending Articles