Textfile
Textfile
Text files: Each line of text is terminated with a special character called EOL (End of Line), which is
the new line character (‘\n’) in python by default.
Six File Access Modes:
Read Only (‘r’) : Open text file for reading. If no file exists: I/O error. default mode.
Read and Write (‘r+’): Open the file for reading and writing. If no file exists: I/O error.
Write Only (‘w’) : Open the file for writing. If file exists, the data is truncated and over-written.
The handle is positioned at the beginning of the file. Creates the file if the file does not exist.
Write and Read (‘w+’) : Open the file for reading and writing. If file exists, the data is truncated
and over-written. The handle is positioned at the beginning of the file.
Append Only (‘a’): Open the file for writing. Creates the file if the file does not exist. The
handle is positioned at the end of the file. The data being written will be inserted at the end, after
the existing data.
Append and Read (‘a+’) : Open the file for reading and writing. Creates the file if the file does
not exist. The handle is positioned at the end of the file. The data being written will be inserted at
the end, after the existing data.
Points:
No module is required to be imported for this open() function.
(File_object = open(r"File_Name","Access_Mode")
file1 = open("myfile.txt","r+")
file1.seek(0)
file1.seek(0)