[Tutor] how to track an entry in a large text file
Mitya Sirenef
msirenef at lightbird.net
Thu Jan 17 00:32:30 CET 2013
On 01/16/2013 04:22 PM, 3n2 Solutions wrote:
> Say I have a text file (example below) that has multiple records with
> the same format but not always the same number of lines. Each record
> is separated by the line that starts with “Examining file” as in below
> example. If you notice, the 3D Val is not there for the second record.
> How do I report that the “3D Val” is not present for that particular
> record “8866W2310089.txt”?
> Thanks to Alan for his reply.
>
>
>
> Examining file: 5521W2310000.txt
>
> Duration : 0h : 59m
> First meas : week : 86 : 1721
> Last meas : week : 89 : 1721
>
> Min val : 15
> Max val : 18
> 3D : 3600 100.0%
>
> summary Total Missed Rate
> epoch1 : 1378 0 0\1000
> epoch2 : 2154 1 0\1000
>
>
>
> Examining file: 8866W2310089.txt
>
> Duration : 0h : 59m
> First meas : week : 87 : 1721
> Last meas : week : 84 : 1721
>
> Min val : 16
> Max val : 19
>
> summary Total Missed Rate
> epoch1 : 1378 0 0\1000
> epoch
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
If the file isn't very huge, you can split by "Examining file: ",
then iterate over the list, check if '3D' is in the item; if it
isn't, split the item by newlines and print first line.
HTH, - mitya
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
More information about the Tutor
mailing list