Python – How to read a file into a list?
Python example to read a log file, line by line into a list. # With ‘\n’, [‘1\n’, ‘2\n’, ‘3’] with open(‘/www/logs/server.log’) as f: content = f.readlines() # No ‘\n’, [‘1’, ‘2’, ‘3’] with open(‘/www/logs/server.log’) as f: content = f.read().splitlines() 1. Read File -> List 1.1 A dummy log file. d:\\server.log a b c d 1 …