Python 列表 : Appending a string and removing ALL quotations

标签 python list append

下面的代码取 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/

相关文章:

java - 类别/子类别 : How to get all subcategories(their subcategories too) for given category?

string - 将AppleScript列表转换为字符串

python - 在 Python 3 中打开文件、重新格式化并写入新文件

Redis: append 到字符串的位置

jquery - 向 append 在 .click 上的 DIV 添加关闭按钮

python - bool 数组上的 numpy.bitwise_and 的 numba 速度较慢

python - 如何组合和重叠两个张量?

python - 如何将列表 append 到 pandas 列,系列?

python - 减少模板匹配的失误(使用透明模板)

java - LAMP中 'P'有什么意义?为什么是 PHP、Perl 或 Python?