I stand corrected, apparently it is possible to read and write pixels using that (undocumented) indexing technique, at least with some image formats. Learn something new everyday... ;-)
Anyway what's wrong with your program is the line:
r, g, b = [x/255.0 for x in r, g, b]
which changes the value ofx
which is already being used to iterate over the pixel coordinates. Simply changing it to another variable name as shown below will make your code do what you want:
r, g, b = [c/255.0 for c in r, g, b]
(Note, better yet, change it to the following and remove the line preceding it)
r, g, b = [c/255.0 for c in px[x,y]]
After doing that, here's the image that will result — displayed as RGB, not HSL, to show that the structure is indeed mutable: