z412290894 发表于 2021-12-23 14:36:29

字符串如何转换成字典

代码简化如下:
import easygui as eg
choice_land=[{0: 'KK'}, {1: 'K'}, {2: 'K'}, {3: 'K'}, {4: 'KK'}, {5: 'K'}, {6: 'K'}, {7: 'K'}]
result = eg.choicebox(msg='原始板块要插入的位置:', choices=choice_land)

执行之后选择一个选项
result的值是字符串"{4: 'KK'}"
请问如何把"{4: 'KK'}"转换成{4: 'KK'}

逃兵 发表于 2021-12-23 14:41:04

eval()函数了解一下
>>> eval("{4: 'KK'}")
{4: 'KK'}
页: [1]
查看完整版本: 字符串如何转换成字典