Multi-line size specification reading with python
Read multiple lines with python
I tried to read the file in multiple lines with python, so I will leave it as a memorandum.
The size is specified by the number of characters, and if you specify the number of characters halfway, the line
Read to the end.
Line breaks are not counted. Zero reads all lines
Version: Python 3.8.5
windows 10
File contents
> abcdefghijklmnopqrstuvwxyz
12345678901234567890
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Specify the middle of the first line.py
def readlines( fname ):
with open( fname, 'r') as f:
readData = f.readlines( 20 )
return readData
if __name__ == '__main__':
fname = './Dmy.txt'
readData = readlines( fname )
print( f' readData = {type(readData)} {readData}')