English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Python has a set of methods that can be used for file objects.
Method | Description |
---|---|
close() | Close the file. |
detach() | Return the separated raw stream (raw stream) from the buffer. |
fileno() | Return the numeric representation of the stream from the perspective of the operating system. |
flush() | Refresh the internal buffer. |
isatty() | Return whether the file stream is interactive. |
read() | Return the file content. |
readable() | Return whether it is possible to read the file stream. |
readline() | Return a line in the file. |
readlines() | Return the list of lines in the file. |
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 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 list of strings to a file. |
In our Python file tutorial Learn more about file operations on Python.