python dictionary conversion from string?

Posted by shahjapan on Stack Overflow See other posts from Stack Overflow or by shahjapan
Published on 2010-05-07T08:51:33Z Indexed on 2010/05/07 8:58 UTC
Read the original article Hit count: 219

Filed under:
|
|
|

if I've string like

"{ partner_name = test_partner}" OR " { partner_name : test_partner }

its an example string will be very complex with several special characters included like =, [ , ] , { , }

what will be the best way to convert it into a python object - so I can process it

I tried with eval but it requires " ' " for string, but how can we add this special character \' before starting and ending of every word, I tried regular express re.findal('\w+') but it fails when my string contains ' _ ' or like characters as it will separate the string by ' _ '

Object of this question is my application needs, user friendly language as input - and I thought Json Dict will be good - but user is lazzy to put " ' " before and after of each string...

then I thought for yaml but its also complex, if anybody can suggest better user friendly input which I use as python object - then please help me out.

© Stack Overflow or respective owner

Related posts about python

Related posts about eval