Line indexing in Python

seafoid fitzpadj at tcd.ie
Fri Dec 18 16:26:58 EST 2009


Rory,

You are a gentleman!

Thank you very much for your suggestion!

Kind Regards,
Seafoid.


Rory Campbell-Lange wrote:
> 
> On 18/12/09, seafoid (fitzpadj at tcd.ie) wrote:
>> http://old.nabble.com/Parsing-file-format-to-ensure-file-meets-criteria-to26837682.html
> 
> Your specification is confusing. However I suggest you break it down
> the code so that the steps in your programme are logical. Good luck.
> 
> # example psuedocode
> headers = {}
> header_clauses = {}
> current_header = None
> 
> def header_parser (input):
>     split input into parts
>     make unique header desciptor
>     check not in headers else abort with error (?)
>     add descriptor to headers hash
>     # eg descriptor 1 = [attrib1, attrib2, attrib3]
>     return descriptor
> 
> def clause_parser (input, current_header):
>     if current_header is None: abort
>     split clause into parts
>     store in array in header_clauses [current_header]
>     # this will make a data structure like this:
>     # header_clauses = {
>     #       descriptor1 = {[ clause parts ], [ clause parts ], ... }
>     #       descriptor2 = {[ clause parts ], [ clause parts ], ... }
> 
> def comment_parser (input)
>     pass
> 
> # now run over the file
> for l in lines:
>     if l[0] == 'c':
>         comment_parser(l)
>     elif l[0] == 'p':
>         current_header = header_parser(l)
>     else:
>         clause_parser(l, current_header)
> 
> # now that we have stored everything, check the data
> for h in headers:
>     attrib1, attrib2, attrib3  = headers[h]
>     for c in header_clauses:
>         iterate over the arrays of clause parts either adding them
>         up or comparing them to the header attributes
>         
> -- 
> Rory Campbell-Lange
> Director
> rory at campbell-lange.net
> 
> Campbell-Lange Workshop
> www.campbell-lange.net
> 0207 6311 555
> 3 Tottenham Street London W1T 2AF
> Registered in England No. 04551928
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: http://old.nabble.com/Line-indexing-in-Python-tp26845253p26849944.html
Sent from the Python - python-list mailing list archive at Nabble.com.




More information about the Python-list mailing list