本文整理汇总了Python中IPython.core.getipython.get_ipython方法的典型用法代码示例。如果您正苦于以下问题:Python getipython.get_ipython方法的具体用法?Python getipython.get_ipython怎么用?Python getipython.get_ipython使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.core.getipython
的用法示例。
在下文中一共展示了getipython.get_ipython方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __exit__
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def __exit__(self, exc_type, exc_val, exc_tb):
"""
Reset the namespace.
"""
get_ipython().kernel._running_namespace = None
if self._previous_filename:
self.ns_globals['__file__'] = self._previous_filename
elif '__file__' in self.ns_globals:
self.ns_globals.pop('__file__')
if not self.current_namespace:
_set_globals_locals(self.ns_globals, self.ns_locals)
if self._previous_main:
sys.modules['__main__'] = self._previous_main
elif '__main__' in sys.modules and self._reset_main:
del sys.modules['__main__']
if self.filename in linecache.cache:
linecache.cache.pop(self.filename)
示例2: set_display_settings
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def set_display_settings():
"""Enable notebook output settings if running in a jupyter notebook"""
from IPython.core.getipython import get_ipython
from ipykernel.zmqshell import ZMQInteractiveShell
from bokeh.io import output_notebook
from bokeh.resources import Resources
from bokeh.io.state import curstate
ipython_instance = get_ipython()
if ipython_instance is not None:
if isinstance(ipython_instance, ZMQInteractiveShell):
_IPYTHON_INSTANCE = True
# Defer to previous call to ``output_notebook`` so that users
# can specify their own notebook type and Bokeh resources
if curstate().notebook_type is None:
# Inline resources uses bokeh.js from the local version.
# This enables offline usage.
output_notebook(Resources('inline'), hide_banner=True)
示例3: autonotify
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def autonotify(self, line):
# Record options
args = parse_argstring(self.autonotify, line)
self.options["body"] = args.message.lstrip("\'\"").rstrip("\'\"")
self.options['autonotify_after'] = args.after
self.options['autonotify_output'] = args.output
### Register events
ip = get_ipython()
# Remove events if they're already registered
# This is necessary because jupyter makes a new instance everytime
pre, post = self.__class__._events
if pre and pre in ip.events.callbacks['pre_run_cell']:
ip.events.callbacks['pre_run_cell'].remove(pre)
if post and post in ip.events.callbacks['post_run_cell']:
ip.events.callbacks['post_run_cell'].remove(post)
# Register new events
ip.events.register('pre_run_cell', self.pre_run_cell)
ip.events.register('post_run_cell', self.post_run_cell)
self.__class__._events = self.pre_run_cell, self.post_run_cell
示例4: post_run_cell
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def post_run_cell(self):
options = dict(self.options)
# Set last output as notification message
if self.options.get('autonotify_output'):
last_output = get_ipython().user_global_ns['_']
# Don't use output if it's None or empty (but still allow False, 0, etc.)
try:
if last_output is not None and len(str(last_output)):
options['body'] = str(last_output)
except ValueError:
pass # can't convert to string. Use default message
# allow notify to stop autonotify
if not self.__class__.notification_uuid:
return
# Check autonotify options and perform checks
elif self.check_after():
pass
# maybe add other triggers here too
# example/idea: autonotify if browser window not in focus
else:
return
self.display_notification(options, self.__class__.notification_uuid)
示例5: enable
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def enable(dataframe=True, series=True):
"""
Automatically use qgrid to display all DataFrames and/or Series
instances in the notebook.
Parameters
----------
dataframe : bool
Whether to automatically use qgrid to display DataFrames instances.
series : bool
Whether to automatically use qgrid to display Series instances.
"""
try:
from IPython.core.getipython import get_ipython
except ImportError:
raise ImportError('This feature requires IPython 1.0+')
ip = get_ipython()
ip_formatter = ip.display_formatter.ipython_display_formatter
if dataframe:
ip_formatter.for_type(pd.DataFrame, _display_as_qgrid)
else:
ip_formatter.type_printers.pop(pd.DataFrame, None)
if series:
ip_formatter.for_type(pd.Series, _display_as_qgrid)
else:
ip_formatter.type_printers.pop(pd.Series)
示例6: attach_exception_hook
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def attach_exception_hook():
"""Injects async exception hook into the sys.excepthook."""
try:
# detect whether we're running in IPython
__IPYTHON__
except NameError:
shell = None
else:
# override ipython's exception handler if in a shell.
# we need to do this because ipython overrides sys.excepthook
# so just the else block doesn't cover that case.
from IPython.core.getipython import get_ipython
# this may be None if __IPYTHON__ is somehow defined, but we are not
# in fact in a shell
shell = get_ipython()
if shell is not None:
shell.set_custom_exc((BaseException,), ipython_custom_exception_handler)
else:
global is_attached, original_hook
if is_attached:
sys.stderr.write("Warning: async exception hook was already attached.\n")
return
original_hook = sys.excepthook
sys.excepthook = async_exception_hook
is_attached = True
示例7: _get_globals_locals
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def _get_globals_locals():
"""Return current namespace."""
if get_ipython().kernel.is_debugging():
pdb = get_ipython().kernel._pdb_obj
ns_locals = pdb.curframe_locals
ns_globals = pdb.curframe.f_globals
else:
ns_locals = None
ns_globals = get_ipython().user_ns
return ns_globals, ns_locals
示例8: _set_globals_locals
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def _set_globals_locals(ns_globals, ns_locals):
"""Update current namespace."""
if get_ipython().kernel.is_debugging():
pdb = get_ipython().kernel._pdb_obj
pdb.curframe.f_globals.update(ns_globals)
if ns_locals:
pdb.curframe_locals.update(ns_locals)
else:
get_ipython().user_ns.update(ns_globals)
if ns_locals:
get_ipython().user_ns.update(ns_locals)
示例9: post_mortem_excepthook
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def post_mortem_excepthook(type, value, tb):
"""
For post mortem exception handling, print a banner and enable post
mortem debugging.
"""
ipython_shell = get_ipython()
ipython_shell.showtraceback((type, value, tb))
p = pdb.Pdb(ipython_shell.colors)
if not type == SyntaxError:
# wait for stderr to print (stderr.flush does not work in this case)
time.sleep(0.1)
_print('*' * 40)
_print('Entering post mortem debugging...')
_print('*' * 40)
# add ability to move between frames
p.send_initial_notification = False
p.reset()
frame = tb.tb_next.tb_frame
# wait for stdout to print
time.sleep(0.1)
p.interaction(frame, tb)
# ==============================================================================
# runfile and debugfile commands
# ==============================================================================
示例10: interaction
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def interaction(self, frame, traceback):
"""
Called when a user interaction is required.
If this is from sigint, break on the upper frame.
If the frame is in spydercustomize.py, quit.
Notifies spyder and print current code.
"""
if self._pdb_breaking:
self._pdb_breaking = False
if frame and frame.f_back:
return self.interaction(frame.f_back, traceback)
if (frame is not None
and "spydercustomize.py" in frame.f_code.co_filename
and "exec_code" == frame.f_code.co_name):
self.onecmd('exit')
else:
self.setup(frame, traceback)
if self.send_initial_notification:
self.notify_spyder(frame)
if get_ipython().kernel._pdb_print_code:
self.print_stack_entry(self.stack[self.curindex])
self._cmdloop()
self.forget()
# --- Methods overriden for skipping libraries
示例11: reset
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def reset(self):
"""
Register Pdb session after reset.
"""
super(SpyderPdb, self).reset()
kernel = get_ipython().kernel
kernel._register_pdb_session(self)
示例12: notify_spyder
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def notify_spyder(self, frame=None):
"""Send kernel state to the frontend."""
if frame is None:
frame = self.curframe
if frame is None:
return
kernel = get_ipython().kernel
# Get filename and line number of the current frame
fname = self.canonic(frame.f_code.co_filename)
if PY2:
try:
fname = unicode(fname, "utf-8")
except TypeError:
pass
lineno = frame.f_lineno
# Set step of the current frame (if any)
step = {}
if isinstance(fname, basestring) and isinstance(lineno, int):
step = dict(fname=fname, lineno=lineno)
# Publish Pdb state so we can update the Variable Explorer
# and the Editor on the Spyder side
kernel._pdb_step = step
try:
kernel.publish_pdb_state()
except (CommError, TimeoutError):
logger.debug("Could not send Pdb state to the frontend.")
示例13: set_sympy_forecolor
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def set_sympy_forecolor(self, background_color='dark'):
"""Set SymPy forecolor depending on console background."""
if os.environ.get('SPY_SYMPY_O') == 'True':
try:
from sympy import init_printing
from IPython.core.getipython import get_ipython
if background_color == 'dark':
init_printing(forecolor='White', ip=get_ipython())
elif background_color == 'light':
init_printing(forecolor='Black', ip=get_ipython())
except Exception:
pass
# --- Others
示例14: _load_autoreload_magic
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def _load_autoreload_magic(self):
"""Load %autoreload magic."""
from IPython.core.getipython import get_ipython
try:
get_ipython().run_line_magic('reload_ext', 'autoreload')
get_ipython().run_line_magic('autoreload', '2')
except Exception:
pass
示例15: frontend_request
# 需要导入模块: from IPython.core import getipython [as 别名]
# 或者: from IPython.core.getipython import get_ipython [as 别名]
def frontend_request(blocking=True, timeout=None):
"""
Send a request to the frontend.
If blocking is True, The return value will be returned.
"""
if not get_ipython().kernel.frontend_comm.is_open():
raise CommError("Can't make a request to a closed comm")
# Get a reply from the last frontend to have sent a message
return get_ipython().kernel.frontend_call(
blocking=blocking,
broadcast=False,
timeout=timeout)