Steve Horsley wrote: > Kristina KudriaĊĦova wrote: > >> 1 Nov 2005 09:19:45 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]>: >> >>> Hi, I have a file with this content: >>> >>> zzzz zzzzz zzz zzzzz >>> ... >>> xxxxxxx xxxxxxxxxx xxxxx 34.215 >>> zzzzzzz zz zzzz >>> ... >>> >> >> Hi, >> >> I'd suggest doing this: >> >> f = file('...') >> for line in f: >> if 'xxxxxxx xxxxxxxxxx xxxxx' in line: >> var = float(line[len('xxxxxxx xxxxxxxxxx xxxxx'):].strip()) >> f.close() > > > I think I prefer "if line.startswith('xxxxxxx xxxxxxxxxx xxxxx'):" . > Feels cleaner to me.
Especially if any "z" lines might include the magic pattern. -- http://mail.python.org/mailman/listinfo/python-list