+1 vote
in Programming Languages by (11.9k points)

My file has just one column. I want to read the entire file once so that I can create a list using the records in the file. 

E.g.

The file has the following content and I want to generate a list using these records.

0000001

0000062

0000063

0000111

0000124

0000137

0000149

0000150

1 Answer

0 votes
by (21.4k points)

You can use the read() function to read the entire file.

Here is a python code to convert the records into a list. The records are in file 'oleg.txt'.

>>> with open('oleg.txt', 'r') as f:
...     recs = f.read()
...
>>> rec_list = recs.strip().split('\n')
>>> rec_list
['0000001', '0000062', '0000063', '0000111', '0000124', '0000137', '0000149', '0000150']

...