Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
295 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 +


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...