Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use this command:


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

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.

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

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)
share|improve this answer
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 at 16:15

Try this instead:

os.system('raspistill -o image'+ thenumber +'.jpg')
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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