I wish I could ask this question in context, but I don't have enough rep to comment and ask my question there, so I have to make a new post. I am trying to use the code from this comment:
https://stackoverflow.com/a/21034111/432509
I am working in Python in Houdini at school, so I am limited on what libraries I can utilize to what they have installed, so I was going to use the pure python implementation to write some data out as a PNG map, but I am running into an error in this line:
def saveAsPNG(array, f):
import struct
if any([len(row) != len(array[0]) for row in array]):
raise ValueError, "Array should have elements of equal size"
#First row becomes top row of image.
flat = []; map(flat.extend, reversed(array))
#Big-endian, unsigned 32-byte integer.
buf = b''.join([struct.pack('>I', ((0xffFFff & i32)<<8)|(i32>>24) )
for i32 in flat]) #Rotate from ARGB to RGBA.
data = write_png(buf, len(array[0]), len(array))
#f = open(filename, 'wb')
f.write(data)
f.close()
I am getting the following error:
TypeError: unsupported operand type(s) for &: 'int' and 'str'
Unfortunately I am not familiar with all of this syntax and as such I am not able to repair the error myself. Any clues?