Hi folks I am using ros noetic and i have to create 12 file name as x.bag and x ranging upto 12. code is following.
import rospy
import os
for x in range(12):
cmd='rosbag record -o /home/mubashir/catkin_ws/src/germany1_trush/rosbag/x.bag /web_cam --duration 5 '
os.system(cmd)
how I get vlaue of x in cmd.
creating 12 file of 5sec duration using os.while having different name i am not able to acess value of x inside cmd
CodePudding user response:
I'm not sure I understand your question exactly. I think what you want is to run the following command 12 times (from 0 to 11):
import rospy
import os
for x in range(12):
cmd = f'rosbag record -o /home/mubashir/catkin_ws/src/germany1_trush/rosbag/{x}.bag /web_cam --duration 5'
os.system(cmd)
You probably want 1..12 which you can easily do with {x 1}
.
BTW, this is called a "Literal String Interpolation", aka f-string. Pretty handy.