Python File Handling

Python File Handling Part 2

File handling is one of the important feature in programming languages. Python provides a way to handle(read, write & modify) both text files as well as binary files. This tutorial will cover read(), readlines(), seek() and tell() functions in detail.

➠ There are various functions available in Python for File handling. Click the function to get more detail about that function.
Read: The read() function can be used to read the content of file. The read() function can takes one optional parameter i.e Integer parameter which will return 'n' characters from the postion of cursor. By default, content of open file can be read only once as read() function will leave the cursor at the end of the file.

ReadLine: The readline() function can be used to read one line at a time from the file, starting from the beginning of cursor till the end of the line. Output of the readline() function also includes the newline character if present as line separator.

ReadLines: The readlines() function returns each line (beginning from the start of cursor till end of file) as items in the list. Output of the readlines() function also includes the newline character if present as line separator.

Seek: The seek() function can be used to move cursor at the required position.

Tell: The tell() function can be used to get the current position of the cursor in the file.

****Visit File Handling part 3 for more functions