
File methods
Below are the top six file methods in python:- Tell()
- Seek()
- Flush()
- Fileno()
- truncate()
- isatty()
Syntax and purpose
tell()
Purpose: This method will return the cursor position of the file pointer from the beginning of the file. It will tell the current cursor position. The first character index in files is zero just like the string index.
fileobject.tell()
seek()
Purpose: This method will move the cursor position from one position to the specified position from the beginning of the file. Here, the cursor will be sought to a particular location.
fileobject.seek(position)
Syntax:
flush()
Purpose: This method will clean out the internal buffer. Before writing the text in the file, it is best practice to clear out that the internal buffer can be cleared.
fileobject.flush()
fileno()
Purpose: This method will return the file number i.e. a file descriptor as an integer value. If an operating system does not use a file descriptor of the file then an error may occur.
Syntax:
fileobject.fileno()
truncate()
Purpose: This method will resize the file based on the given number of bytes. The current position will be used if the size is not specified.
Syntax:
fileobject.truncate(size)
0 Comments
Thanks for your message. We will get back you.