Python list在字符串周围加双引号并传递给API,API要求将其作为双引号字符串的列表传递
要传递的API数据:
data = {
"styles" : styleList
}
当我手动输入:
["A123", "B123", "C131", "D231"]
但不包括:
['A123', 'B123', 'C131', 'D231']
尝试过但没有帮助的事情:
styleList = ["\"" + style + "\"" for style in styleList]
styleList = [style.replace("'","") for style in styleList]
styleList = json.dumps(styleList)
所有这些都只对打印有用,而不是通过API
您需要列表的字符串表示形式
使用
styleList = ["\"" + style + "\"" for style in styleList]
可以围绕列表中的项目创建:['a','b'] > ['"a"','"b"']
使用
repr
将创建列表的字符串表示:repr()如果你也需要引用数字,请使用
相关问题 更多 >
编程相关推荐