Dictionary and String Conversion eval () and STR () Functions
>>> C = "{'origin _ name': U' \ u7ea2 \ u91d1 \ u9f991 ', 'material _ Code': u'000000', 'id ': 13 }"
>>> C
"{'Origin _ name': U' \ u7ea2 \ u91d1 \ u9f991 ', 'material _ Code': u'000000', 'id': 13 }"
>>> D = eval (c)
>>> D
{'Origin _ name': U' \ u7ea2 \ u91d1 \ u9f991 ', 'material _ Code': u'000000', 'id': 13}
>>> E = STR (d)
>>> E
"{'Origin _ name': U' \ u7ea2 \ u91d1 \ u9f991 ', 'material _ Code': u'000000', 'id': 13 }"
Exec statements are used to execute Python statements stored in strings or files. For example, we can generate a string containing Python code at runtime, and then execute these statements using exec statements. The following is a simple example.
>>> Exec 'print "Hello World "'
Hello World
The eval statement is used to calculate the valid Python expression stored in the string. The following is a simple example.
>>> Eval ('2*3 ')
Sometimes there are coding problems, and we need
Tagname = eval (tagname. Decode ("utf8"), or
Tagname = eval (tagname. Replace ("\ r \ n", ""). Decode ("utf8 "))
The best method is to use JSON
Try: # For python <2.6 or people using a newer versionof simplejson import simplejson as jsonworkflow t importerror: # For Python> = 2.6 import JSON
Dictionary and String Conversion eval () and STR () Functions
>>> C = "{'origin _ name': U' \ u7ea2 \ u91d1 \ u9f991 ', 'material _ Code': u'000000', 'id ': 13 }"
>>> C
"{'Origin _ name': U' \ u7ea2 \ u91d1 \ u9f991 ', 'material _ Code': u'000000', 'id': 13 }"
>>> D = eval (c)
>>> D
{'Origin _ name': U' \ u7ea2 \ u91d1 \ u9f991 ', 'material _ Code': u'000000', 'id': 13}
>>> E = STR (d)
>>> E
"{'Origin _ name': U' \ u7ea2 \ u91d1 \ u9f991 ', 'material _ Code': u'000000', 'id': 13 }"
Exec statements are used to execute Python statements stored in strings or files. For example, we can generate a string containing Python code at runtime, and then execute these statements using exec statements. The following is a simple example.
>>> Exec 'print "Hello World "'
Hello World
The eval statement is used to calculate the valid Python expression stored in the string. The following is a simple example.
>>> Eval ('2*3 ')
Sometimes there are coding problems, and we need
Tagname = eval (tagname. Decode ("utf8"), or
Tagname = eval (tagname. Replace ("\ r \ n", ""). Decode ("utf8 "))
The best method is to use JSON
Try: # For python <2.6 or people using a newer versionof simplejson import simplejson as jsonworkflow t importerror: # For Python> = 2.6 import JSON