user2216280
user2216280

Reputation: 73

how to iterate in a string in python?

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?

Upvotes: 0

Views: 83

Answers (1)

UltraInstinct
UltraInstinct

Reputation: 44464

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)

Upvotes: 5

Related Questions