The Python Stringio class is used to handle strings, and because they operate like file operations, they can be considered as in-memory files.
1. Create Stringio
2. Common operation:
Write,writelines, GetValue, Seek, ReadLine, ReadLines
>>> from Stringio import stringio>>> buff = Stringio () >>> buff.write (' Hello ') >>> Buff.writelines ([' World ', '! ']) >>> buff.len11>>> buff.seek (0) >>> buff.read () ' helloworld! ' >>> buff.getvalue () ' helloworld! ' >>> buff.read () ">>> buff.readlines () []>>> buff.seek (0) >>> buff.readlines () [' Helloworld! ']
Cstringio is a version of its C language implementation.
See some usage of Stringio on StackOverflow to receive the output of the function to the standard output, and then continue to use it in another function. The basic idea is to create a Stringio object that assigns the object to Sys.stdout so that the data entered into the stdout is in the Stringio object in memory, and the object is GetValue () to get the data printed out of the function.
Python Stringio class