What is the correct way to use pygame.Color names when using unicode_literals?
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>> pygame.ver
'1.9.2pre'
>>> pygame.Color('red')
(255, 0, 0, 255)
>>> from __future__ import unicode_literals
>>> pygame.Color('red')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid argument
When
unicode_literalsis enabled, Python 2 interprets string literals the same way as Python 3. That is,'red'is a Unicode string (calledunicodein Python 2,strin 3), andb'red'is a bytestring (calledstrorbytesin Python 2,bytesin Python 3).Since
pygame.Coloronly accepts a bytestring, pass itb'red':>>> from __future__ import unicode_literals >>> pygame.Color('red') Traceback (most recent call last): File "", line 1, in ValueError: invalid argument >>> pygame.Color(b'red') (255, 0, 0, 255)