Python Stringio class

Source: Internet
Author: User
Tags python stringio

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.