2

I want to use this command:

thenumber=0

os.system('raspistill -o image(thenumber).jpg')
time.sleep(3)
thenumber=thenumber+1

I have imported the OS and Time so this script should work.

My aim is to have it so when it takes a picture, it will change the name of the file and create a new one, so we can have multiple pictures from one script.

2
  • Your question's a wee bit vague - is there an error message of some kind? What happens when you run it? – goobering Feb 12 '16 at 13:57
  • 2
    Hello and welcome! Could you please explain what the problem is (just like goobering asked)? – Ghanima Feb 12 '16 at 14:22
6

Use format strings.

'raspistill -o image{0:02d}.jpg'.format(thenumber)

The {0:02d} formats the parameter to format as a 2 digit integer with leading zeros.

I also recommend using the subprocess package instead of os.system it gives you more control over the how the command is run and how the out put is captured. In the simple case os.system can be replaced with subprocess.call.

return_code = subprocess.call('raspistill -o image{0:02d}.jpg'.format(thenumber), shell=True)
1
  • For readability, I'd prefer to format the string in one line, and feed it to the function in a second, but good answer. +1 – Jacobm001 Feb 12 '16 at 16:15
2

Try this instead:

os.system('raspistill -o image'+ thenumber +'.jpg')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.