sdl2.ext.compat - Python Version Compatibility Helpers¶
The sdl2.ext.compat module provides various helper functions for writing
code that works seamlessly on both Python 2.7 and Python 3.x.
-
ISPYTHON2¶ True, if executed in a Python 2.x compatible interpreter,Falseotherwise.
-
ISPYTHON3¶ True, if executed in a Python 3.x compatible interpreter,Falseotherwise.
-
sdl2.ext.compat.utf8(x)[source]¶ Converts input to a unicode string in a Python 2/3 agnostic manner.
If a
bytesobject is passed, it will be decoded as UTF-8. This function returnsunicodefor Python 2 andstrfor Python 3.Parameters: x – Input to convert to a unicode string. Returns: stron Python 3.x, orunicodeon Python 2.7.
-
sdl2.ext.compat.stringify(x, enc='utf-8')[source]¶ Converts input to a
strin a Python 2/3 agnostic manner.If the input is
unicodeand the Python version is 2.7, theencparameter indicates the encoding to use when converting the input to a non-unicode string. If the input isbytesand the Python version is 3.x, theencparameter indicates the encoding to use to decode the input into a unicode string.Parameters:
-
sdl2.ext.compat.byteify(x, enc='utf-8')[source]¶ Converts input to
bytesin a Python 2/3 agnostic manner.If the input is a unicode string, the
encparameter indicates the encoding to use when encoding the input tobytes.Parameters: