We now have a youtube channel. Subscribe!

A Complete List of Python File Methods



Hello dear readers! Welcome back to another edition of our tutorial on Python. In this tutorial guide, i am going to be dropping you guys with the complete table of Python file methods.

A file object is created using the open function and below is the list of functions which can be called on this object -

Sr.No.Methods with Description
1file.close()
Close the file. A closed file cannot be read or written any more.
2file.flush()
Flush the internal buffer, like stdio's fflush. This may be a no-op on some file-like objects.
3file.fileno()
Returns the integer file descriptor that is used by the underlying implementation to request I/O operations from the operating system.
4file.isatty()
Returns True if the file is connected to a tty(-like) device, else False.
5file.next()
Returns the next line from the file each time it is being called.
6file.read([size])
Reads at most size bytes from the file (less if the read hits EOF before obtaining size bytes).
7file.readline([size])
Reads one entire line from the file. A trailing newline character is kept in the string.
8file.readlines([sizehint])
Reads until EOF using readline() and return a list containing the lines. If the optional sizehint argument is present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (possibly after rounding up to an internal buffer size) are read.
9file.seek(offset[, whence])
Sets the file's current position
10file.tell()
Returns the file's current position
11file.truncate([size])
Truncates the file's size. If the optional size argument is present, the file is truncated to (at most) that size.
12file.write(str)
Writes a string to the file. There is no return value.
13file.writelines(sequence)
Writes a sequence of strings to the file. The sequence can be any iterable object producing strings, typically a list of strings.


The above methods is going to be discussed in details in our future tutorials.

Alright guys! This is where we are rounding up for this tutorial guide. In our next tutorial, we are going to be studying about the Python File close() Method.

Feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain