Use re package with text file : Split « Regular Expressions « Python Tutorial






import re
f = open('whodata.txt', 'r')
for eachLine in f.readlines():
         print re.split('\s\s+', eachLine)
f.close()








16.6.Split
16.6.1.with re.split you can split on any sequence of space characters and commas
16.6.2.The maxsplit argument indicates the maximum number of splits allowed:
16.6.3.Split Output of Unix who Command (rewho.py)
16.6.4.Use re package with text file
16.6.5.Regular-expression string manipulation.