- 1
How to read each .rpt file line by line using python?
I have multiple folders and each folder contains a report file. I'm trying to read each report file line by line but I can only be able to search for the report files but couldn't be able to read. Here is the link I tried https://code.sololearn.com/#py Here, am trying to read the .rpt file using python. Any help would be appreciated
1 Answer
0
Once you open the file you can use the readlines method:
file = open("path/to/file.rpt", "r")
file_lines = file.readlines()
This method returns a list of strings (Each string is one line of the file)
Remember that each line also contains (or should contain) a line break at the end.
It may differ depending on what EoL (End Of Line) the file uses (I am not sure tho, so do your own research).
By default, Windows uses CRLF, and Linux and OSX use LF
An end of line with type of LF would be "\n"
I don't remember how a CRLF EoL is.