[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack



Hi,

Personally, I think all functions should return 4 values.  Most code like:
r,g,b = #blah(...)
can be pretty easily retrofitted like:
try:r,g,b = #blah(...)
except:r,g,b,a = #blah(...)

I actually anticipated this problem, so most of my code looks like:
color = #blah(...)
#use color[0],color[1],color[2]

As you can see, whether color[3] exists is irrelevant.  When I need alpha, I check the docs to find which function(s) to use. 

However, for all functions in the future, I think it's best to err on the side of sending the user more information rather than less...

Ian