Reading Custom Delimited file in python 1

Reading Custom Delimited file in python

f= open("f.txt",mode='r',encoding='utf8', newline='\r\n')

# use enumerate to show that second line is read as a whole
for i, line in enumerate(fd):   
    print(i, line)

Here is what the above code is Doing:
1. The open() function opens the file f.txt in read mode.
2. The for loop iterates over the file object fd.
3. The enumerate() function adds a counter to the iterable.
4. The counter is stored in the variable i.
5. The line variable stores the value of the current line.
6. The print() function prints the line number and the line.

Similar Posts