StringIO.readline() returns ''

M

Max

I'm using StringIO for the first time (to buffer messages recieved from
a socket). I thought it would be a simple matter of writing the stuff to
the buffer and then calling readline, but that doesn't seem to work:
''

I expected buf.readline() to return 'Foo\n'. What am I doing wrong?

--Max
 
F

Fredrik Lundh

Unknown said:
I'm using StringIO for the first time (to buffer messages recieved from
a socket). I thought it would be a simple matter of writing the stuff to
the buffer and then calling readline, but that doesn't seem to work:

''

I expected buf.readline() to return 'Foo\n'. What am I doing wrong?

you forgot to rewind the file:
'Foo\n'

</F>
 
T

timothy.soehnlin

You can also just type buf.getvalue() which returns the current
StringIO buffer as a python string, without the rewinding
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,292
Messages
2,571,494
Members
48,178
Latest member
SusanaHam4

Latest Threads

Top