0

I want to make some montage in ImageMagick which is called by Python via os.system() with 100 jpegs files.

Here's the command:

cmd='montage '+file[i]+' '+file[i+1]+' '+file[i+2]+' '+file[u+3]+'     +file[i+4]+'...+file[i+99]

I would like to know how could I avoid to write all file[i+x] entries. Is this possible?

2
  • 1
    cmd = "montage " + " ".join(files) Assuming all your filenames are in 'file' Commented Sep 26, 2016 at 8:04
  • Use subprocess() instead. os.system() is really, really outdated. Proposed depricated. Commented Sep 26, 2016 at 8:22

1 Answer 1

5

To join 100 strings with a space starting at ith index:

cmd = "montage " + " ".join(file[i:i+100])

.. where file[i:i+100] will return a sub-sequence starting at i, and ending at (i + 100 - 1)

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

1 Comment

Downvoted before you added the first explanation, just one line of code is not enough for a good answer for me. Now it's good

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.