Discuss / Python / 疑问

疑问

Topic source

StringIO到底是什么呢?

StringIO().write('hello') 5

为什么会有个5出来呢,前面没有讲到这个啊

In [224]: StringIO? Init signature: StringIO(initial_value='', newline='\n') Docstring: Text I/O implementation using an in-memory buffer.

The initial_value argument sets the value of object. The newline argument is like the one of TextIOWrapper's constructor. Type: type

In [225]: StringIO.write? Signature: StringIO.write(self, s, /) Docstring: Write string to file.

Returns the number of characters written, which is always equal to the length of the string. Type: method_descriptor

哈哈,听说题主打算放弃,去学别的课程了? 学到半截了都能放弃,你也算条汉子, 按这个节奏,不出意外的话,不久的将来能在php论坛遇见你。

确实是写进去了 只不过返回的是写进去的字符数量 hello 有5个字母


  • 1

Reply