Answer by user6035109 for Reopening a closed stringIO object in Python 3
I have a nice hack, which I am currently using for testing (Since my code can make I/O operations, and giving it StringIO is a nice get-around).If this problem is kind of one time thing:st =...
View ArticleAnswer by 9716278 for Reopening a closed stringIO object in Python 3
When you f.close() you remove it from memory. You're basically doing a deref x, call x; you're looking for a memory location that doesn't exist.Here is what you could do in stead:import ioa = 'Me, you...
View ArticleAnswer by raphaelhuefner for Reopening a closed stringIO object in Python 3
No, there is no way to re-open an io.StringIO object. Instead, just create a new object with io.StringIO().Calling close() on an io.StringIO object throws away the "file contents" data, so re-opening...
View ArticleAnswer by ldiary for Reopening a closed stringIO object in Python 3
The builtin open() creates a file object (i.e. a stream), but in your example, f is already a stream.That's the reason why you get TypeError: invalid fileAfter the method close() has executed, any...
View ArticleReopening a closed stringIO object in Python 3
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...
View Article