Tuesday, June 12, 2012

Python read file splitlines alternatives

Due to the low memory conditions of a VPS, I found this better.

#create an array
file1TextArray=[]

file1 = open('/root/file1new.txt', 'r')
for line in file1:
        file1TextArray.append(line[:-2])
file1.close()

Tested on Python3
Note this deletes the last two characters because the text file had \r\n as the new line delimeter

No comments:

Post a Comment