[Tutor] help on StringIO

kinuthia muchane muchanek at gmail.com
Tue May 27 11:01:19 CEST 2008



> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Mon, 26 May 2008 06:06:42 -0400
> From: inhahe <inhahe at gmail.com>
> Subject: [Tutor] help on StringIO
> To: tutor at python.org
> Message-ID:
> 	<da776a8c0805260306l4dd6769bx8907a1ee2712b754 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Can someone explain to me how to use StringIO?
> 
> Python 2.5.2 Stackless 3.1b3 060516 (release25-maint, Apr  2 2008, 19:04:14) [MS
> C v.1310 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import StringIO
> >>> s = StringIO.StringIO()
> >>> s.write('hi')

> >>> print s.read()
> 
> >>>
> 
> Is this a bug?
> 
When you use the write method you move the cursor to the end of the
word, just as Kent says. You can use the tell() method which returns
your current position in the file-like object to confirm this:

>>> import StringIO
>>> s = StringIO.StringIO()
>>> s.write('hi')
>>> s.tell()
2




More information about the Tutor mailing list