python - 打印以同一行的逗号分隔值打印

标签 python syntax-error

我无法在不打印新行的情况下将输出打印在一行上,以下代码显示语法错误:

print( "tiers found:"+eval("str.lower(tier.attrib['TIER_ID'])"), end=', ')
                                                                        ^
SyntaxError: invalid syntax

但这很好用:
print( "tiers found:"+eval("str.lower(tier.attrib['TIER_ID'])"))

打印语句在for循环中,我需要将输出打印为逗号分隔的列表。
那么,这里出了什么问题?

最佳答案

您为什么要对完全理智的声明使用eval?

from __future__ import print_function
print('tiers found: {0}'.format(tier.attrib['TIER_ID'].lower()), end=',')

关于python - 打印以同一行的逗号分隔值打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18485554/

相关文章:

javascript - python flask : How to handle send_file on the client side

python - 我想要一个类' __init__ 将对象添加到列表中,但我想防止冗余并且 "if self not in objectlist"不工作

function - Postgres 9.0.4 : Error calling function which returns a ROWTYPE from within another function

php - PHP MYSQL PREPARE语法问题(意外T_STRING)

python - 为什么我得到的语法无效

objective-c - 当我将字符串粘贴到Xcode中时,总是会出现错误,必须重新输入

python - 仅安装依赖项 - setuptools

python - 为什么打印带有 unicode 字符的文件不会生成表情符号?

python - Pandas : date as year, 月份 ... 在日期时间的分隔列中

c# - 错误4无效的表达词 'else'