Python write error - TypeError: unsupported operand type(s) for %: 'tuple' and 'tuple'
Python write error - TypeError: unsupported operand type(s) for %: 'tuple' and 'tuple'
我有一个 Python 脚本打印 3 个值 x, y, z
如下 -
1
,2
,WELCOME_TO_ROS
现在我想将这些值写入以下格式的头文件中 -
#define WELCOME_TO_ROS 1,2, "WELCOME_TO_ROS"
我目前的尝试 -
f.write('#define %s %d, %d, "%s"') % (z, x, y, z)
正确的格式应该是什么?我收到以下错误 -
TypeError: unsupported operand type(s) for %: 'tuple' and 'tuple'
创建元组
tp = (1,2,"WELCOME_TO_ROS")
写入文件句柄为f的头文件
f.write('#define {2} {0},{1}, "{2}"'.format(tp[0], tp[1], tp[2]))
我有一个 Python 脚本打印 3 个值 x, y, z
如下 -
1
,2
,WELCOME_TO_ROS
现在我想将这些值写入以下格式的头文件中 -
#define WELCOME_TO_ROS 1,2, "WELCOME_TO_ROS"
我目前的尝试 -
f.write('#define %s %d, %d, "%s"') % (z, x, y, z)
正确的格式应该是什么?我收到以下错误 -
TypeError: unsupported operand type(s) for %: 'tuple' and 'tuple'
创建元组
tp = (1,2,"WELCOME_TO_ROS")
写入文件句柄为f的头文件
f.write('#define {2} {0},{1}, "{2}"'.format(tp[0], tp[1], tp[2]))