What about a generator and xreadlines for those really large files: py>def recordbreaker(recordpath, seperator='#'): ... rec = open(recordpath ,'r') ... xrecord = rec.xreadlines() ... a =[] ... for line in xrecord: ... sep = line.find(seperator) ... if sep != -1: ... a.append(line[:sep]) ... out = ''.join(a) ... a =[] ... a.append(line[sep+1:]) ... yield out ... else: ... a.append(line) ... if a: ... yield ''.join(a) ... rec.close() ... py>records = recordbreaker('/tmp/myrecords.txt') py>for item in records: ... print item
M.E.Farmer [EMAIL PROTECTED] wrote: > Hi, > I know that i can do readline() from a file object. > However, how can I read till a specific seperator? > for exmple, > if my files are > > name > profession > id > # > name2 > profession3 > id2 > > I would like to read this file as a record. > I can do this in perl by defining a record seperator; > is there an equivalent in python? > thanks -- http://mail.python.org/mailman/listinfo/python-list