python convert a long numeric txt file like for example the first 16 milion Pi numbers and save it to a list

Viewed 23

python convert a long numeric txt file like for example the first 16 million Pi numbers and save it to a list

import pandas as pd
file='/home/pp/Pictures/pi.txt'
read_file=pd.read_csv(file)
for row in read_file:
    print(','.join(row))
1 Answers

If each line in the file is a digit, then

with open(file, 'r') as f:
    digits = f.readlines()

If you need to split the digits (not just one digit per line in the file)

with open(file, 'r') as f:
    digits = list(f.readlines()[0])
Related