doc
0
Q:

python read lines

with open("file.txt") as file_in:
    lines = []
    for line in file_in:
        lines.append(line)
21
with open(filename) as f:
    content = f.readlines()
# you may also want to remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content] 
5
f = open("file.txt", 'r')
print(f.readlines())  # array of file lines
5
f = open("filename")
lines = f.readlines()
1
with open('yourfile.txt','r') as f:
    lines = f.readlines()
    f.close()
1
# Reads first line of file
f.readline()
1

New to Communities?

Join the community