如果我想查看str.replace()
功能:help(str.replace)
结果是:
Help on method_descriptor:
replace(...)
S.replace(old, new[, count]) -> str
Return a copy of S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced.
(END)
但是如何使用帮助file.read
或readlines
?
例如,help(file.read)
和help(read)
都是错误:
>>> help(file)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'file' is not defined
>>> help(file.read)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'file' is not defined
>>> help(read)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'read' is not defined
如何使用帮助查看文件功能?
答案 0 :(得分:2)
已从Python 3中删除file
类型。请改为io
module:
>>> import io
>>> help(io.TextIOBase.read)
Help on method_descriptor:
read(...)
Read at most n characters from stream.
Read from underlying buffer until we have n characters or we hit EOF.
If n is negative or omitted, read until EOF.