0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.