我无法在不打印新行的情况下将输出打印在一行上,以下代码显示语法错误:
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/