我在一个循环中,变量y在每次迭代中都有一个列表。
输入:

y= ['0', '1', '2', '3', '4', '5', '6']

期望输出:
create pressure at points 0 1 2 3 4 5 6

我尝试使用简单访问
print "create pressure at points d% d% d% d% d% d% d%" % ( y[0], y[1], y[2], y[3], y[4], y[5], y[6])

给出错误:
KeyError: 0

我想将列表中的所有值解析为另一个软件,为此我需要打印它们。以特定的方式
sensorik.cmd('create pressure at points 0 1 2 3 4 5 6')

如果它可以保存为y[0]等,那么这些可以被解析为
sensorik.cmd('create pressure at points d% d% d% d% d% d% d% ' % (y[0], y[1], y[2], y[3], y[4], y[5], y[6]))

有什么建议吗?

最佳答案

只是列表

y= ['0', '1', '2', '3', '4', '5', '6']
print 'create pressure at points', ' '.join(y)
# create pressure at points 0 1 2 3 4 5 6

关于python - 将列表中的整数解析为软件的命令行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36629273/

10-15 14:54