File Handling in Python
Data Files There are two types of data files: 1. Text file: Stores data in ASCII or Unicode encoding. Each line ends with a special EOL (End Of Line) character. 2. Binary file: Stores data in the same format without encoding. The lines of data are not delimited with any EOL character. Opening Files The open() function is used to open a file. By default, the file is opened in "read" mode. myfile = open("details.txt") However, you can also mention the "read" mode while opening a file. myfile = open("details.txt", "r") In the above code, "myfile" is the file object or file handle. To open a file from a specific location: myfile = open("c:\\Users\\details.txt", "r") Double backslashes are provided because it is an escape sequence for representing a single backslash. If you want to use single backslash, then use a raw string. myfile = open(r"c:\users\details.txt", "r") When the path of the fi...