Skip to content

Instantly share code, notes, and snippets.

@rhee
Last active May 16, 2022 01:20
Show Gist options
  • Save rhee/c038393822eabec681092b6941ef1f1e to your computer and use it in GitHub Desktop.
Save rhee/c038393822eabec681092b6941ef1f1e to your computer and use it in GitHub Desktop.
"""
# https://gist.github.com/rhee/c038393822eabec681092b6941ef1f1e
# fake_ipython.py
Usage:
from fake_ipython import get_ipython
"""
from inspect import stack
def get_ipython():
class ipython:
def system(self, str):
print('>>> system() ignored:', str)
def run_cell_magic(self, magic, rest, content):
print('>>> cell_magic() exec:', magic, rest, content)
_globals=stack()[1].frame.f_globals
exec(content,_globals)
def run_line_magic(self, magic, rest):
print('>>> line_magic() ignored:', magic, rest)
return ipython()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment