How to parse a text block?

Sergey Smirnov smirnoffs at
Fri Nov 26 14:06:35 CET 2010

Hi all.

I have a lot of text blocks that looks like this one

*** Layer 3 Message type: CP-Data
Device: MS1
Time: 19:57:44.71
CP-User data
  length : 37
    Message type indicator (MTI) : (1) RP-DATA

The question is how to parse given text block into a dictionary that looks
like the dictionary given below?

{'Device':'MS1','Time':'Time: 19:57:44.71','CP-User
data':{'length':'37','RPDU':{'Message type indicator (MTI)':'(1) RP-DATA'}}}

Any other thoughts about reading that kind of text?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list