Search code examples
jupyter-notebookipythoncython

string in #define macro in cython in notebook


I have an iPython notebook and I can specify cython macros fine with something like

# distutils: define_macros=NAME=VALUE

but now I want to pass VALUE as a string "VALUE"

# distutils: define_macros=NAME="VALUE"

It IS passing a string, but it's passing "__Pyx_L1_".

I tried '"VALUE"' and \"VALUE\" but they give compile errors because ' is for a character and \ becomes a "stray".


Solution

  • It looks like a bug to me, so probably for the time being one should use the following work around, using extra_compile_args-option of cython-magic:

    %%cython -c=-DNAME="VALUE"
    # here code
    

    adding -DNAME="VALUE" to command line of the compiler and thus defining NAME.