[IPython-User] %%cython_annotate magic

Dave Hirschfeld dave.hirschfeld@gmail....
Mon Jul 16 09:00:45 CDT 2012


Hi devs,
I'm finding the %%cython magic very handy for prototyping (and debugging)
my cython code. One thing I've found to be very handy is the little 
`cython_annotate` function below in combination with the Notebook/QtConsole
HTML display capabilities.


def cython_annotate(path):
    import os
    os.system("cython.py -a {path}".format(path=path))
    with open(os.path.splitext(path)[0] + ".html") as istream:
        html = istream.read()
    return html
#

from IPython.display import HTML
HTML(cython_annotate(path_to_pyx_file))


I did have to hack the %%cython magic to return the pyx filename, but 
obviously a better solution would be to have a %%cython_annotate magic
defined which did it all for you. 

I had a look at doing it myself but didn't feel confident that I 
knew enough to make a good job of it so I've opened a Github issue
(https://github.com/ipython/ipython/issues/2143) in the hope that
someone else may have the same itch. 

Regards,
Dave



More information about the IPython-User mailing list