0

I have an iterating function for i in [database]

Every i has with it associated multiple values, which I can extract with .operators .

I am interested in two values of each i, its name and its image. I write each name down on a txt file with:

txt = open("name list.txt", "a")
txt.write(i.name)
txt.write("\n")
txt.close()

This gives me a basic list with all the names. I then I try to add all images to a PNG file like so:

png = open("image list.png", "ab") #also tried ab+
png.write(i.image)
png.close()

But, even though I used append, the result is one single image, specifically the last. How do I add the rest?

edit: whoops, brackets.

YoungSnek
  • 1
  • 2
  • What are you going to be opening this file in, and how exactly do you expect it to behave when it opens one file with multiple images? – glibdud Mar 21 '17 at 16:40
  • You mean, what is my end goal? To have all images combined into one PNG file I can open like any other PNG. – YoungSnek Mar 21 '17 at 17:27
  • "Any other PNG" generally only has one image. What do you expect your multi-image file to look like? – glibdud Mar 21 '17 at 17:29
  • A collage of all the others basically. The first image is pasted, and then the second next to it and so forth. – YoungSnek Mar 21 '17 at 17:58
  • You'll have to combine them into a single image before writing to the file. If you're using PIL, for example, see [this](http://stackoverflow.com/questions/30227466/combine-several-images-horizontally-with-python). – glibdud Mar 21 '17 at 18:01
  • Seems like there is no version for 3.x as of now for that? (http://www.pythonware.com/products/pil/) – YoungSnek Mar 21 '17 at 18:05
  • If you already have the images loaded in Python, just use whatever library generated them. – glibdud Mar 21 '17 at 18:06
  • I see what needs to be done now, thank you. If you could repost that as an answer I can close this question. – YoungSnek Mar 21 '17 at 18:10

0 Answers0