Skip to content

Looking for print/plot shorthand magics #6739

Discussion options

You must be logged in to vote

I found this - https://stackoverflow.com/questions/30240156/how-to-write-an-ipython-alias-which-executes-in-python-instead-of-shell

Seems to work.

from IPython.core.magic import register_line_magic

@register_line_magic
def d(data):
    code = f"display({data})"
    print("-->", code)
    exec(code, globals())

del d 
a = "asdf"
%d a

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by blazespinnaker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant