1

I'm trying to turn a red smiley(PPM) into a green smiley(PPM) by modifying the source code with python (I use PyCharm CE). When I print the source file, I have this :

b'P6\n100 100\n255\n\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff...

The goal is to modify some triplets (\xff\xff\xff) to change pixels color. So I keep the header(P6\n100 100\n255\n) aside and I create an array to modify just:(\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff...)

After modification, (I turn the red pixels into green pixels) I add a new code:

[255, 255, 255, 255, 255, 255, 255, 255, 255, 255, ...

How to turn this array into the same format(Ascii) than I had at the beginning; which was (\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff...)?

The smiley

Paul Lecomte
  • 141
  • 1
  • 10
  • 1
    Hint: what you had was not ASCII but a [*bytearray*](https://docs.python.org/3.1/library/functions.html#bytearray) – look it up in the documentation. – Jongware Nov 25 '18 at 09:57

0 Answers0