Python文件方法
- Previous Page Python Collection Methods
- Next Page Python Keywords
Python有一组可用于文件对象的方法。
方法 | 描述 |
---|---|
close() | 关闭文件。 |
detach() | 从缓冲区返回分离的原始流(raw stream)。 |
fileno() | 从操作系统的角度返回表示流的数字。 |
flush() | 刷新内部缓冲区。 |
isatty() | 返回文件流是否是交互式的。 |
read() | 返回文件内容。 |
readable() | 返回是否能够读取文件流。 |
readline() | 返回文件中的一行。 |
readlines() | 返回文件中的行列表。 |
seek() | Change the file position. |
seekable() | Return whether the file allows us to change the file position. |
tell() | Return the current file position. |
truncate() | Adjust the file size to the specified size. |
writeable() | Return whether it is possible to write to the file. |
write() | Write the specified string to a file. |
writelines() | Write a string list to a file. |
Please visit our Python File Handling Tutorial Learn more about file objects.
- Previous Page Python Collection Methods
- Next Page Python Keywords