File Handling Functions in Python

File Handling Functions in Python

File handling functions in Python are used when dealing with files. They are used to open and close them, to read from and write into, and various other purposes. Some of those functions are mentioned below in the form of a table.

 

File Handling Functions in Python Description
close() This method is used to close the specified file object which first has to opened.
detach() This method returns the separated raw stream from the buffer.
fileno() This method returns file descriptor of the file stream as a number.
flush() This method is used to flush the internal buffer.
isatty() This method returns True if the file stream is interactive, if not, returns False.
open() This method is used to open a file and returns a file object if the file was opened successfully.
read() This method is used to read the contents of specified file object.
readable() This method returns True if the file stream can be read, if not, returns False.
readline() This method reads one line from the specified file object.
readlines() This method reads a list of lines from the specified file object.
seek() This method is used to change the position of the specified file object.
seekable() This method returns True, if the specified file object allows us to change the file position, if not, returns False.
tell() This method returns the current position of the specified file object.
truncate() This method is used to resize the specified file object to a specific size.
writable() This method returns True if the specified file object can be written to, if not, returns False.
write() This method is used to write the specified string object to the specified file object.
writelines() This method is used to write a list of specified string objects to the specified file object.
Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *