Nikolaus Rath, 28.04.2013 22:52:
> I have the following code:
>
> def do_stuff(barf)
> cdef char* buf
> assert isinstance(barf, str)
> if sys.version_info < (3,): # Python 3
> barf_bytes = barf.encode('utf-8', 'surrogateescape')
> else: # Python 2
> barf_bytes = barf
> buf = barf_bytes
> # ...
>
>
> However, I really dislike the runtime check on the Python version. In
> theory, the condition could already be evaluated at C compile time.
>
> Is there a way to do that? Unfortunately there seem to be no predefined
> definitions for sys.version_info like there are for os.uname..
from cpython.version cimport PY_MAJOR_VERSION
if PY_MAJOR_VERSION < 3: ...
Stefan