Greg Hennessy
Greg Hennessy

Reputation: 527

best method for parsing a file using python

I would appreciate some advice on how to parse a file. I have a file generated by another party, and it is a dump of data. I would prefer to use python to parse the file, but if a C based method would be easier I would use that. The file is ascii text, in the form:

Sequence { 
 Target ManualDump
 Camera xxxx
 Timestamp "20170623133425"
 ID NULL
 FrameSize.x 512
 FrameSize.y 512
 Frames 
[ { 
 SequenceNumber 0
 frameStart "23/06/2017 13:32:29.707459"
 Stars 
[ 
 ] } { 
 SequenceNumber 1
 frameStart "23/06/2017 13:32:34.767027"
 Stars 
[ { 
 Catalog "YYYYY" 
 Index 13016559
 Name NULL 
} { 
 Catalog "YYYYY" 
 Index 13016572
 Name NULL 
} 
 ] } { 
 SequenceNumber 2
 frameStart "23/06/2017 13:32:39.826595"
 Stars 
[ { 
 Catalog "YYYYY" 
 Index 13016559
 Name NULL 
} { 
 Catalog "YYYYY" 
 Index 13016572
 Name NULL 
} 
 ] }
] }

I have definitions of Sequence, Frames, Stars, etc, for example a Frame is:

Frame
{
    SequenceNumber INTEGER
    FrameStart STRING                                            
    FrameStop STRING                                             
    FieldDerotationDegrees FLOAT                                 
    BoresightDegrees STRUCTURE TelescopeCoord                    
    BoresightSkyPos STRUCTURE SkyCoord                           
    Stars ARRAY STRUCTURE Star                                   
    BoresightCoord STRUCTURE PixelCoord                          
}

I've trimmed some details to fit, but I don't think I'm deleted anything important.

I can probably cobble up a had written parser to parse this file, but I was wondering if someone could recommend a package/tool that seems meant for the job.

Thank you.

Upvotes: 0

Views: 73

Answers (1)

Bill Bell
Bill Bell

Reputation: 21663

This looks a natural candidate for pyparsing

Upvotes: 1

Related Questions