下面的代码取 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)
我是一名优秀的程序员,十分优秀!