我試圖把用戶輸入的字典和使用下面的代碼在屏幕上顯示它的內容如何利用用戶輸入字典,並顯示其在Python
import ast
a = input("Please enter a dictionary: ")
d = ast.literal_eval(a)
print d
but this error is occuring
File "x.py", line 3, in <module>
d = ast.literal_eval(a)
File "/usr/lib64/python2.6/ast.py", line 68, in literal_eval
return _convert(node_or_string)
File "/usr/lib64/python2.6/ast.py", line 67, in _convert
raise ValueError('malformed string')
ValueError: malformed string
發佈您通過的輸入。 –
輸入:{'a':1,'b':2} –
它適用於我.. –