+1 vote
in Programming Languages by (73.8k 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

+1 vote
by (348k points)
selected by
 
Best answer

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']


...