How to parse a text block?

Sergey Smirnov smirnoffs at gmail.com
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
  RPDU
    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?

Thanks,
Sergey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101126/48992e9b/attachment.html>


More information about the Python-list mailing list