En Sun, 13 Dec 2009 07:28:24 -0300, Peter Otten <__pete...@web.de> escribió:
bsneddon wrote:

I am going to read a text file that is an export from a control
system.
It has lines with information like

base=1 name="first one" color=blue

I would like to put this info into a dictionary for processing.

import shlex
s = 'base=1 name="first one" color=blue equal="alpha=beta" empty'
dict(t.partition("=")[::2] for t in shlex.split(s))
{'color': 'blue', 'base': '1', 'name': 'first one', 'empty': '', 'equal':
'alpha=beta'}

Brilliant!

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to