我尝试从字典中的数据库中插入一些值,它工作正常,但它以这种格式插入值。"S"
而不是S
.
我尝试使用函数split()
,例如:
cat_sName = dumps(item_meta_data[int(menu_item.id)]['short_name'].split('"'))
当我打印 cat_sName 它打印这个值:
['', 'S', '']
代替S
我尝试从字典中的数据库中插入一些值,它工作正常,但它以这种格式插入值。"S"
而不是S
.
我尝试使用函数split()
,例如:
cat_sName = dumps(item_meta_data[int(menu_item.id)]['short_name'].split('"'))
当我打印 cat_sName 它打印这个值:
['', 'S', '']
代替S
您可以使用strip
而不是split
摆脱引号:
>>> '"S"'.strip('"')
'S'
它们最初来自哪里?
您应该使用strip()
函数删除双引号:
像这样
cat_sName = dumps(item_meta_data[int(menu_item.id)]['short_name'].strip('"'))
strip
函数删除内容,而split
函数根据分隔符将字符串拆分为列表。您应该剥离以进行删除工作
尝试这个 :
cat_sName = dumps(item_meta_data[int(menu_item.id)]['short_name'].split('"')[1])