from IPython.core.magic import register_cell_magic @register_cell_magic def run_and_save(line, cell): 'Run and save python code block to a file' with open(line, 'wt') as fd: fd.write(cell) code = compile(cell, line, 'exec') exec(code, globals()) %%run_and_save hello.py class Hello: def __init__(self): pass
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter