8/26/23, 10:58 PM Python File Methods
Dark code
Tutorials Exercises Get Certified Services Menu Bootcamps Spaces Sign Up Log in
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP
REACT
Python File Methods
❮ Previous Next ❯
Python has a set of methods available for the file object.
Method Description
close() Closes the file
detach() Returns the separated raw stream from the buffer
fileno() Returns a number that represents the stream, from the operating system's perspective
flush() Flushes the internal buffer
isatty() Returns whether the file stream is interactive or not
read() Returns the file content
readable() Returns whether the file stream can be read or not
readline() Returns one line from the file
readlines() Returns a list of lines from the file Dark mode
https://www.w3schools.com/python/python_ref_file.asp k d 1/6
8/26/23, 10:58 PM Python File Methods
Dark code
seek()
Tutorials
Change the file position
Exercises Get Certified Services Menu Bootcamps Spaces Sign Up Log in
seekable() Returns whether the file allows us to change the file position
HTML
CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP
REACT
tell() Returns the current file position
truncate() Resizes the file to a specified size
writable() Returns whether the file can be written to or not
write() Writes the specified string to the file
writelines() Writes a list of strings to the file
Learn more about the file object in our Python File Handling Tutorial.
❮ Previous Log in to track progress Next ❯
Dark mode
https://www.w3schools.com/python/python_ref_file.asp k d 2/6