1

I can do

from cpython.version cimport PY_MAJOR_VERSION
if PY_MAJOR_VERSION == 3:
    spam = bytes("spam")

However, if I try to do the detection at compile time, it fails.

from cpython.version cimport PY_MAJOR_VERSION
IF PY_MAJOR_VERSION == 3:
    spam = bytes("spam")

Compile-time name 'PY_MAJOR_VERSION' not defined

Does anyone know a way to do this?

aebrahim
  • 36
  • 3
  • Use the same technique that was suggested in the answers to [this question](http://stackoverflow.com/questions/26225187/try-statement-in-cython-for-cimport-for-use-with-mpi4py). You can get the version in Python from `sys.version_info`. – IanH Oct 15 '14 at 22:32
  • Looks pretty similar to http://stackoverflow.com/questions/3826458/cython-conditional-compile-based-on-external-value – Veedrac Oct 16 '14 at 15:19
  • 1
    Thanks for the suggestion, @IanH - that looks like what I want. – aebrahim Oct 16 '14 at 23:17

0 Answers0