devi thapa wrote:
hi all
I have one normal text file. I need to parse the file, that too in an associative way .
suppose that below is the normal textfile

name='adf'
id  =1
value=344


there are many approaches to config files. But
in your special example, it looks like a simplified
mapping, so

parsed=eval("dict(%s)" % ",".join(line
                             for line
                             in file("textfile")
                             if line.strip()
                                 )
            )

>>> parsed['name']
'adf'

but of course eval() is dangerous, so feel free to
explore more then this one solution.

Regards
Tino

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

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

Reply via email to