extract to dictionaries

Teguh Iskanto tiskanto at gmail.com
Thu May 28 22:34:21 EDT 2009


You can create this modularly by :
1. parse the file and cut this into different chunks ( look for 'end' ) then
you have two chunks for param 1 & 2
2. once you have those chunks then process each chunk with your own
processing based on your parameters ( 1 or 2 )
3. then based on your individual param, create a process to populate your
dict
4. done

hint: "pydoc string"  ( I'm assuming that you already know about regex, if
not then use this : "pydoc re"  )
BTW: I've used this methods to parse  cisco/contivity configs

HTH

On Fri, May 29, 2009 at 9:03 AM, Marius Retegan
<marius.s.retegan at gmail.com>wrote:

> Hello
> I have simple text file that I have to parse. It looks something like
> this:
>
> parameters1
>     key1 value1
>     key2 value2
> end
>
> parameters2
>     key1 value1
>     key2 value2
> end
>
> So I want to create two dictionaries parameters1={key1:value1,
> key2:value2} and the same for parameters2.
>
> I woud appreciate any help that could help me solve this.
> Thank you
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090529/2bbd4de7/attachment-0001.html>


More information about the Python-list mailing list