Created
May 24, 2012 05:54
-
-
Save ellisonbg/2779717 to your computer and use it in GitHub Desktop.
Cython inline IPython magic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "cython_inline_magic" | |
}, | |
"nbformat": 3, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": true, | |
"input": [ | |
"from IPython.core.magic import register_line_cell_magic" | |
], | |
"language": "python", | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": true, | |
"input": [ | |
"@register_line_cell_magic", | |
"def cython_inline(line, cell):", | |
" import Cython", | |
" # Cython.inline returns the value of that is returned in the code block,", | |
" # it would be nice if a magic function could have a return value that get's sent to pyout", | |
" # so the user can get to it. As it stands now, there is no way to access that return value", | |
" # so I just print it.", | |
" print Cython.inline(cell)" | |
], | |
"language": "python", | |
"outputs": [], | |
"prompt_number": 25 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": true, | |
"input": [ | |
"a = 20", | |
"b = 'hi'" | |
], | |
"language": "python", | |
"outputs": [], | |
"prompt_number": 27 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%%cython_inline", | |
"return a, b" | |
], | |
"language": "python", | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"Compiling /Users/bgranger/.cython/inline/_cython_inline_11f49ea6a373f5cc3519b4d2446e484d.pyx because it changed.", | |
"Cythonizing /Users/bgranger/.cython/inline/_cython_inline_11f49ea6a373f5cc3519b4d2446e484d.pyx", | |
"(20, 'hi')" | |
] | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": [ | |
"", | |
"" | |
] | |
} | |
], | |
"prompt_number": 27 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": true, | |
"input": [ | |
"" | |
], | |
"language": "python", | |
"outputs": [] | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment