Skip to content

Instantly share code, notes, and snippets.

@catherinedevlin
Last active December 28, 2015 00:19
Show Gist options
  • Save catherinedevlin/7412177 to your computer and use it in GitHub Desktop.
Save catherinedevlin/7412177 to your computer and use it in GitHub Desktop.
Simple IPython magic that gets a value; used to demo a problem
from IPython.core.magic import Magics, magics_class, line_magic
@magics_class
class GetValueMagics(Magics):
@line_magic
def getvalue(self, line=''):
var_name = line.split()[0]
return self.shell.user_ns[var_name]
def load_ipython_extension(ip):
ip.register_magics(GetValueMagics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment