1、StringIO模块

2、string模块

3、pprint模块

4、struct模块

5、uuid模块

6、itertools

7、prettytable

1、StringIO

 (1)使用

  from io import stringio

StringIO模块主要用于在内存缓冲区中读写数据。

1、read

用法:

s.read([n]):参数n用于限定读取的长度,类型为int,默认为从当前位置读取对象s中所有的数据。读取结束后,位置被移动。

 

2、readline

用法:

s.readline([length]):length用于限定读取的结束位置,类型为int,缺省为None,即从当前位置读取至下一个以'\n'为结束符的当前行。读位置被移动。

 

3、readlines

用法:

s.readlines():读取所有行

 

4、write

用法:

s.write(s):从读写位置将参数s写入到对象s。参数为str或unicode类型,读写位置被移动。

 

5、writeline

用法:

s.writeline(s):从读写位置将list写入给对象s。参数list为一个列表,列表的成员为str或unicode类型。读写位置被移动

 

6、getvalue

用法:

s.getvalue():返回对象s中的所有数据

 

7、truncate

用法:

s.truncate([size]):从读写位置起切断数据,参数size限定裁剪长度,默认为None

 

8、tell

用法:

s.tell()  #返回当前读写位置

 

9、seek

用法:

s.seek(pos[,mode]):移动当前读写位置至pos处,可选参数mode为0时将读写位置移动到pos处,为1时将读写位置从当前位置移动pos个长度,为2时读写位置置于末尾处再向后移动pos个长度。默认为0

 

10、close

用法:

s.close():释放缓冲区,执行此函数后,数据将被释放,也不可再进行操作。

 

11、isatty

用法:

s.isatty():此函数总是返回0。不论StringIO对象是否已被close。

 

12、flush

用法:

s.flush():刷新缓冲区。
StringIO模块方法

相关文章: