I was staring at a piece of Python code I produced, which, though correct, is ugly. Is there a more pythonic way of doing this?
r = self.get_pixel(x,y, RED)
g = self.get_pixel(x,y, GREEN)
b = self.get_pixel(x,y, BLUE)
t = function(r,g,b)
if t:
r2, g2, b2 = t
self.set_pixel(x,y,RED, r2)
self.set_pixel(x,y,GREEN, g2)
self.set_pixel(x,y,BLUE, b2)
The problem is the repetition of the method calls for get_pixel
and set_pixel
. For your information:
RED, GREEN, BLUE = range(3)
Also note that I'd like to preserve code clarity and cleanness.