Stripping non-numbers from a file parse without nested lists?

Lorenzo loluengo at gmail.com
Wed Apr 1 16:21:52 CEST 2009


Maybe you can try a regex, something like

------
import re
pattern = re.compile('^(\d+)/(\d+).*')
def read_data(filename):
       fh = open(filename, "r", encoding="ascii")

       for line in fh:
           if pattern.match(line):
               dip_,dir_ = pattern.match(line).groups()
               dip.append(dip_)
               dir.append(dir_)
-----



More information about the Python-list mailing list