say user gives a number n=3 then I have to create 3 files dynamically. How will I do that? What can be the names of those files. Specifically I want n number of .jpg file created.
say user gives a number n=3 then I have to create 3 files dynamically. How will I do that? What can be the names of those files. Specifically I want n number of .jpg file created.
Assuming you have an image stored in some format (maybe base 64 string?) already, you can do something like:
n = raw_input("Number of files: ")
image_list = ... # your logic for the image data here
n = int(n)
for i in range(n):image = open("image" + str(i) + ".jpg", "w")image.write(image_list[i])image.close()
For clarification, w
means write to filename
(overwriting its contents). If you want to append to a file instead, use a
.
Edit: removed my wrong explanation on +