python - Read file into dictionary and manipulate data -


i trying read text file , delete lines it, if values exceed amount choose.

it's text file holds map , need manipulate values in 3rd column. , write new map different file (or edit same file). note values 3-4 characters long.

this how map looks (relevant values in bold type)

1 979 999 514 383 117 95 1

1 979 1000 514 383 117 95 1

i managed write clean short code reading files. have far:

list = [] line in open('textfile.txt','r').readlines():     list.append(line.strip())     print(line) 

now need way identify relevant values on each line , set condition hold manipulation (deleting values in case).

i've tried compare range in specific line array integer did not work.

i tried placing in 1 string , setting exponential loop delete every characters reside in [6] [10] range (growing exponentially) turned out complicated me.

could me this?

i read data list of lists:

with open('testfile.txt') fin:     data = [line.split() line in fin] 

now can manipulate data in third column:

for line in data:     print line[2] #prints values in third column 

and write out -- here i'll write different file, written input file:

with open('testfile_out.txt','w') fout:     line in data:         fout.write(' '.join(line)+'\n')  

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -