gpt4 book ai didi

Python 列表 : Appending a string and removing ALL quotations

转载 作者:太空宇宙 更新时间:2023-11-03 19:43:35 27 4
gpt4 key购买 nike

下面的代码取 self 正在开发的一个更大的项目。

本节的目的是将输出格式化为列表,任何地方都不带引号。

但是,当我尝试将输出格式化为列表时,它的外面有引号,我浏览了多个论坛,但找不到任何遇到确切问题的人。

编码输入:

colourChart = []
tempColour = tempAlpha

tempColour = "%s" % (', '.join(tempColour)) #! Creates a string, I need it in a List format.
print("What I need it to be formatted as:\n [" + tempColour + "]")

colourChart.append(tempColour) #! Takes previous string, appends to List, adds quotes tho :(
print("What it actually gets formatted as:\n",colourChart)

输出:

What I need it to be formatted as:
[colourAlpha(0.3), colourAlpha(0.4), colourAlpha(0.5), colourAlpha(0.6)]

What it actually gets formatted as:
['colourAlpha(0.3), colourAlpha(0.4), colourAlpha(0.5), colourAlpha(0.6)']

此链接包含我正在测试的 Python 脚本: https://drive.google.com/drive/folders/1y1-SkyUoDYrR1UU0ssJd6izjfNsbwZUJ?usp=sharing

最佳答案

colourChart.append(tempColour.split(","))
print("What it actually gets formatted as:\n",colourChart)

关于Python 列表 : Appending a string and removing ALL quotations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60285382/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com