Introduction string into the dictionary, eval of

The string must have a clear characteristics, or python can not be divided, the idea is a character 
string into a first list, and then added to an empty list, and finally into the dictionary.
get_webinfo DEF ():
str1 = []
config = "A = b = cancellation login"
Result = config.split ( '')
for D in Result:
str1.append (d.split ( "="))
Print (dict ( str1))

eval () function is very powerful, you can directly run the code of conduct python execution,
such as print (eval ( "1 + 2 ")) can get results 3,
can also be passed variable print (eval ( "{ 'name': 'linux ', 'age': age}", { "age": 1822}))
output: { 'name': 'linux
', 'age': 1822} If the string you directly in the form of a dictionary
DEF get_dict ():
config = "{ 'a': 'login', 'b': 'Logout'}"
Print (the eval (config))

Guess you like

Origin www.cnblogs.com/yichuncom/p/10984098.html