how to loop and read from a file, a particular integers or strings using index in python? -


i have in file one.txt:

99999 5286 88888 3478 

i want read numbers 99999, 88888 not other numbers using loop , write file two.txt.

str.split split string on whitespace, eg, "a b c d" become ["a", "b", "c", "d"]

the docs on split: https://docs.python.org/2/library/stdtypes.html#str.split

solution example:

with open('one.txt', 'r') in_file, open('two.txt', 'w') out_file:     in_string in in_file.readlines():         out_file.write(in_string.split()[0])         out_file.write('\n') 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -