Re: StringIO.readline() returns ''

2006-04-10 Thread [EMAIL PROTECTED]
You can also just type buf.getvalue() which returns the current
StringIO buffer as a python string, without the rewinding

-- 
http://mail.python.org/mailman/listinfo/python-list


StringIO.readline() returns ''

2006-04-09 Thread 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:

  buf = StringIO.StringIO()
  buf.write(Foo\n)
  buf.write(Bar\n)
  buf.flush()
  buf.readline()
''

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

--Max
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: StringIO.readline() returns ''

2006-04-09 Thread Fredrik Lundh
Unknown wrote:

 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:

   buf = StringIO.StringIO()
   buf.write(Foo\n)
   buf.write(Bar\n)
   buf.flush()
   buf.readline()
 ''

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

you forgot to rewind the file:

 buf = StringIO.StringIO()
 buf.write(Foo\n)
 buf.write(Bar\n)
 buf.seek(0)
 buf.readline()
'Foo\n'

/F



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: StringIO.readline() returns ''

2006-04-09 Thread Max
Fredrik Lundh wrote:
 you forgot to rewind the file:
 

Thank you.

 
 /F
 

--Max
-- 
http://mail.python.org/mailman/listinfo/python-list