how-to-read-a-file-line-by-line-into-a-list

cat file.txt

asdfasd

asdfasfs

3232323

23232

10.192.168.23

10.12.23.24


r2list.py

x = open("file.txt").read().splitlines()

y = open("file.txt").readlines()


print(x)

print(y)


OUTPUT:

/Users/linda/PycharmProjects/hello/venv/bin/python /Users/linda/PycharmProjects/hello/hello.py

['asdfasd', 'asdfasfs', '3232323', '23232', '10.192.168.23', '10.12.23.24']

['asdfasd\n', 'asdfasfs\n', '3232323\n', '23232\n', '10.192.168.23\n', '10.12.23.24\n']


Process finished with exit code 0