1

I'm currently loading a color value from a text file, and pygame is giving me errors with it. It works fine on my Windows computer, but not on my Linux with identical code. Here's an example of what sort of shenanigans this code is pulling:

color = getSetting('playerColor')  //reads a .ini from SafeConfigParser
print color                        //prints: #f54e4e
print pygame.Color('#f54e4e')      //prints: (245, 78, 78, 255)
print pygame.Color(color)          //throws invalid argument error

The linux-only nature of this leads me to believe it's something to do with encoding. I've heard pygame.Color breaks if future unicode_literals is imported, but it isn't. I'm in python 2.7, pygame 1.9.1

Any string I try to pass directly seems to work just fine.

Matthew Fournier
  • 1,077
  • 2
  • 17
  • 32

1 Answers1

3

It is possible that color is not a str but a unicode object. Try

print pygame.Color(str(color))

You can debug it by printing the type of color object:

print type(color)
Selcuk
  • 57,004
  • 12
  • 102
  • 110
  • That does indeed look like the issue, is there any reason why my SafeConfigParser was working fine and returning a String before, but then suddenly started giving me a Unicode object? – Matthew Fournier Jan 29 '16 at 01:06
  • Just a wild guess but could it be something to do with encoding as you already suggested. See this question: http://stackoverflow.com/questions/1648517/configparser-with-unicode-items – Selcuk Jan 29 '16 at 07:04