可变字符串

作者: 0981b16f19c7 | 来源:发表于2019-07-01 11:55 被阅读0次

    from io import StringIO

    a = "hello world"

    sio = StringIO(a)

    print(sio)

    print(sio.tell()) # 获取当前文件读取指针的位置

    print(sio.read()) # 从当前位置开始读取字符串

    print(sio.getvalue()) # 返回可变字符串的全部内容

    sio.seek(6)

    print(sio.tell())

    print(sio.read())

    sio.write("python")  # 从seek(6)指定的位置开始写入字符串

    print(sio.tell())

    print(sio.read())

    print(sio.getvalue())

    结果:

    <_io.StringIO object at 0x0000000002150F78>

    0

    hello world

    hello world

    6

    world

    17

    hello worldpython

    相关文章

      网友评论

        本文标题:可变字符串

        本文链接:https://www.haomeiwen.com/subject/rkcgcctx.html