下面的代码摘自我正在从事的一个较大的项目。
本节的目的是将输出格式化为列表,并且在任何地方都没有引号。
但是,当我尝试将输出格式设置为列表时,它在外部带有引号,我浏览了多个论坛,但找不到任何出现确切问题的人。
编码输入:
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)