Noob Parsing question

kai.peters at gmail.com kai.peters at gmail.com
Tue Feb 17 23:35:01 EST 2015


> > Given
> >
> > data = '{[<a=14^b=Fred^c=45.22^><a=22^b=Joe^><a=17^c=3.20^>][<a=72^b=Soup^>]}'
> >
> > How can I efficiently get dictionaries for each of the data blocks framed by <> ?
> >
> > Thanks for any help
> 
> The question here is: What _can't_ happen? For instance, what happens
> if Fred's name contains a greater-than symbol, or a caret?
> 
> If those absolutely cannot happen, your parser can be fairly
> straight-forward. Just put together some basic splitting (maybe a
> regex), and then split on the caret inside that. Otherwise, you may
> need a more stateful parser.
> 
> ChrisA

The data string is guaranteed to be clean - no such irregularities occur.



More information about the Python-list mailing list