我有清单:
itemid = ['113222408782', '113223652945', '113222268092', '113223761722', '113222277037', '113223676589', '113214024190', '113227956444', '113222400375', '113222383960', '113223749386', '113213898511', '113223653433', '113214060057', '113212059543', '113223647852', '113212403974', '113222230789', '113212110156', '113213917508', '113223748917', '113212088893', '113213936773', '113212282559', '113222369037', '113223645004', '113214034011', '113223647208', '113222397481', '113212052765', '113212136602', '113212037895', '113222210185', '113223752305', '113212049744', '113212400978', '113212274566', '113218830085', '113203034623', '113222199167', '113223648988', '113223646543', '113223651519', '113222200831', '113213996789', '113214000484', '113213890605', '113222232853', '113222298617', '113223753658', '113222238111', '113194336951', '113223631876', '113222242464', '113212123303', '113222215450', '113214000567', '113223642160', '113223639750', '113214060070', '113223644511', '113194332243', '113212139900', '113222207007', '113222374260', '113223719876', '113194339799', '113223677943', '113212417158', '113212433693', '113227977319', '113223607151', '113212409228', '113215809743', '113214051350']
此列表包含75个值。我使用以下方法将该列表切成20个项目列表:
while len(itemid) > 0:
slice = itertools.islice(itemid, 20)
ha = []
for x in slice:
ha.append(format(x))
var1 = ','.join(ha)
var1返回具有20个值的字符串,如下所示:
113222408782,113223652945,113222268092,113223761722,113222277037,113223676589,113214024190,113227956444,113222400375,113222383960,113223749386,113213898511,113223653433,113214060057,113212059543,113223647852,113212403974,113222230789,113212110156,113213917508
然后我被卡住了:
我正在将其用于eBay api,我想执行以下命令:
api_request = {'ItemID': var1}
并返回:
{'ItemID': '113223748917,113212088893,113213936773,113212282559,113222369037,113223645004,113214034011,113223647208,113222397481,113212052765,113212136602,113212037895,113222210185,113223752305,113212049744,113212400978,113212274566,113218830085,113203034623,113222199167'}
但是我需要返回不带引号的字符串var1:
{'ItemID': 113223748917,113212088893,113213936773,113212282559,113222369037,113223645004,113214034011,113223647208,113222397481,113212052765,113212136602,113212037895,113222210185,113223752305,113212049744,113212400978,113212274566,113218830085,113203034623,113222199167}
我该怎么做?
答案 0 :(得分:1)
引号实际上不是字符串的一部分,它们只是表示它是字符串。因此,您无法删除它们
答案 1 :(得分:0)
您不需要将数组转换为字符串,您必须像这样传递整个对象:
var1 = itertools.islice(itemid, 20)
api_request = {'ItemID': var1}
如果需要将其作为数组传递,为什么要尝试将其转换为格式?
关于, 伊戈尔·奎里诺(Igor Quirino)