Skip to content

Instantly share code, notes, and snippets.

@ellisonbg
Created May 24, 2012 05:54
Show Gist options
  • Save ellisonbg/2779717 to your computer and use it in GitHub Desktop.
Save ellisonbg/2779717 to your computer and use it in GitHub Desktop.
Cython inline IPython magic
Display the source blob
Display the rendered blob
Raw
{
"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