[Tutor] StringIO
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Tue May 23 05:45:46 CEST 2006
> I want to use the module StringIO as read and write strings as files, I
> looked into document but cannot understand. Could anyone give me a
> simple example?
>
> something like:
> from StringIO import *
> fin = StringIO("abc")
> .....
> How can I used fin?
'fin' is a file-like object at this point, so you can do things
like:
fin.read(1)
to get a single byte. The list of things we can do with file-like objects
is here:
http://www.python.org/doc/lib/bltin-file-objects.html
Does this help? Good luck!
More information about the Tutor
mailing list