Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85767
| References | <c41fcec3-ea9f-4cce-8f6b-0f51d8cf3912@googlegroups.com> |
|---|---|
| Date | 2015-02-18 15:16 +1100 |
| Subject | Re: Noob Parsing question |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18802.1424232968.18130.python-list@python.org> (permalink) |
On Wed, Feb 18, 2015 at 3:07 PM, <kai.peters@gmail.com> wrote:
> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Noob Parsing question kai.peters@gmail.com - 2015-02-17 20:07 -0800
Re: Noob Parsing question Chris Angelico <rosuav@gmail.com> - 2015-02-18 15:16 +1100
Re: Noob Parsing question kai.peters@gmail.com - 2015-02-17 20:35 -0800
Re: Noob Parsing question Chris Angelico <rosuav@gmail.com> - 2015-02-18 15:54 +1100
Re: Noob Parsing question kai.peters@gmail.com - 2015-02-18 08:57 -0800
csiph-web