本文整理汇总了Python中IPython.terminal.embed.InteractiveShellEmbed.instance方法的典型用法代码示例。如果您正苦于以下问题:Python InteractiveShellEmbed.instance方法的具体用法?Python InteractiveShellEmbed.instance怎么用?Python InteractiveShellEmbed.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.terminal.embed.InteractiveShellEmbed
的用法示例。
在下文中一共展示了InteractiveShellEmbed.instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ipython
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def ipython(message=None, frame=None):
"""Launch into customized IPython with greedy autocompletion and no prompt to exit.
If stdin is not tty, just issue warning message."""
import sys
if os.isatty(sys.stdin.fileno()):
config = Config({
'InteractiveShell': {'confirm_exit': False, },
'IPCompleter': {'greedy': True, }
})
InteractiveShellEmbed.instance(config=config)(message, local_ns=frame.f_locals, global_ns=frame.f_globals)
else:
warn("==========> IPython cannot be launched if stdin is not a tty.\n\n")
示例2: wrapper
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def wrapper(namespace=namespace, banner=''):
config = load_default_config()
# Always use .instace() to ensure _instance propagation to all parents
# this is needed for <TAB> completion works well for new imports
shell = InteractiveShellEmbed.instance(
banner1=banner, user_ns=namespace, config=config)
shell()
示例3: ipy
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def ipy():
"""Run the IPython console in the context of the current frame.
Useful for ad-hoc debugging."""
from IPython.terminal.embed import InteractiveShellEmbed
from IPython import embed
frame = sys._getframe(1)
with stdio_to_tty():
shell = InteractiveShellEmbed.instance()
shell(local_ns=frame.f_locals, global_ns=frame.f_globals)
示例4: wrapper
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def wrapper(namespace=namespace, banner=''):
config = load_default_config()
# Always use .instace() to ensure _instance propagation to all parents
# this is needed for <TAB> completion works well for new imports
# and clear the instance to always have the fresh env
# on repeated breaks like with inspect_response()
InteractiveShellEmbed.clear_instance()
shell = InteractiveShellEmbed.instance(
banner1=banner, user_ns=namespace, config=config)
shell()
示例5: _ipython
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def _ipython(local, banner):
from IPython.terminal.embed import InteractiveShellEmbed
from IPython.terminal.ipapp import load_default_config
InteractiveShellEmbed.clear_instance()
shell = InteractiveShellEmbed.instance(
banner1=banner,
user_ns=local,
config=load_default_config()
)
shell()
示例6: console
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def console():
"""Starts an interactive IPython console"""
import sys
import builtins
from IPython.terminal.embed import (load_default_config,
InteractiveShell, InteractiveShellEmbed)
header = 'Django debug console'
config = load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell
# save ps1/ps2 if defined
ps1 = None
ps2 = None
try:
ps1 = sys.ps1
ps2 = sys.ps2
except AttributeError:
pass
# save previous instance
saved_shell_instance = InteractiveShell._instance
if saved_shell_instance is not None:
cls = type(saved_shell_instance)
cls.clear_instance()
# Starts shell
retvalue = None
def exit(value=None):
nonlocal retvalue
retvalue = value
try:
builtins.exit = exit
shell = InteractiveShellEmbed.instance(config=config)
shell(header=header, stack_depth=2, compile_flags=None)
InteractiveShellEmbed.clear_instance()
finally:
pass
# restore previous instance
if saved_shell_instance is not None:
cls = type(saved_shell_instance)
cls.clear_instance()
for subclass in cls._walk_mro():
subclass._instance = saved_shell_instance
if ps1 is not None:
sys.ps1 = ps1
sys.ps2 = ps2
return retvalue
示例7: interact
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def interact(self, **kwargs):
from IPython.terminal.embed import InteractiveShellEmbed, load_default_config
import sys
config = kwargs.get('config')
header = kwargs.pop('header', u'')
compile_flags = kwargs.pop('compile_flags', None)
if config is None:
config = load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell
kwargs['config'] = config
frame = sys._getframe(1)
shell = InteractiveShellEmbed.instance(
_init_location_id='%s:%s' % (
frame.f_code.co_filename, frame.f_lineno), **kwargs)
shell(header=header, stack_depth=2, compile_flags=compile_flags,
_call_location_id='%s:%s' % (frame.f_code.co_filename, frame.f_lineno))
InteractiveShellEmbed.clear_instance()
示例8: embed
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def embed(pdb=False):
from IPython.terminal.embed import InteractiveShellEmbed, load_default_config
from IPython import Application, embed, get_ipython
config = load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell
config.InteractiveShellEmbed.pdb = pdb
shell = InteractiveShellEmbed.instance(config=config)
# my hook
shell.set_hook('synchronize_with_editor', synchronize_with_editor)
### di, gu, gv etc...
shell.safe_execfile('/home/ppalucki/workspace/djangoshellhelpers.py')
### start
shell(stack_depth=2)
示例9: _embed_ipython
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def _embed_ipython(self, load_extension=None, kwargs=None):
from IPython.terminal.ipapp import load_default_config
from IPython.terminal.embed import InteractiveShellEmbed
kwargs = kwargs or {}
config = kwargs.get('config')
header = kwargs.pop('header', u'')
compile_flags = kwargs.pop('compile_flags', None)
if config is None:
config = load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell
kwargs['config'] = config
kwargs.setdefault('display_banner', False)
self._ishell = InteractiveShellEmbed.instance(**kwargs)
if load_extension:
load_extension(self._ishell)
# Stack depth is 3 because we use self.embed first
self._ishell(header=header, stack_depth=3, compile_flags=compile_flags)
return self._ishell
示例10: ipython
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def ipython(user_ns=None):
os.environ['IPYTHONDIR'] = ipydir
try:
from IPython.terminal.embed import InteractiveShellEmbed
from traitlets.config.loader import Config
from IPython.terminal.prompts import Prompts, Token
except ImportError:
return simple_repl(user_ns=user_ns)
class CustomPrompt(Prompts):
def in_prompt_tokens(self, cli=None):
return [
(Token.Prompt, 'calibre['),
(Token.PromptNum, get_version()),
(Token.Prompt, ']> '),
]
def out_prompt_tokens(self):
return []
defns = {'os':os, 're':re, 'sys':sys}
defns.update(user_ns or {})
c = Config()
user_conf = os.path.expanduser('~/.ipython/profile_default/ipython_config.py')
if os.path.exists(user_conf):
execfile(user_conf, {'get_config': lambda: c})
c.TerminalInteractiveShell.prompts_class = CustomPrompt
c.InteractiveShellApp.exec_lines = [
'from __future__ import division, absolute_import, unicode_literals, print_function',
]
c.TerminalInteractiveShell.confirm_exit = False
c.TerminalInteractiveShell.banner1 = BANNER
c.BaseIPythonApplication.ipython_dir = ipydir
c.InteractiveShell.separate_in = ''
c.InteractiveShell.separate_out = ''
c.InteractiveShell.separate_out2 = ''
ipshell = InteractiveShellEmbed.instance(config=c, user_ns=user_ns)
ipshell()
示例11: embed2
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def embed2(**kwargs):
"""
Modified from IPython.terminal.embed.embed so I can mess with stack_depth
"""
config = kwargs.get('config')
header = kwargs.pop('header', u'')
stack_depth = kwargs.pop('stack_depth', 2)
compile_flags = kwargs.pop('compile_flags', None)
import IPython
from IPython.core.interactiveshell import InteractiveShell
from IPython.terminal.embed import InteractiveShellEmbed
if config is None:
config = IPython.terminal.ipapp.load_default_config()
config.InteractiveShellEmbed = config.TerminalInteractiveShell
kwargs['config'] = config
#save ps1/ps2 if defined
ps1 = None
ps2 = None
try:
ps1 = sys.ps1
ps2 = sys.ps2
except AttributeError:
pass
#save previous instance
saved_shell_instance = InteractiveShell._instance
if saved_shell_instance is not None:
cls = type(saved_shell_instance)
cls.clear_instance()
shell = InteractiveShellEmbed.instance(**kwargs)
shell(header=header, stack_depth=stack_depth, compile_flags=compile_flags)
InteractiveShellEmbed.clear_instance()
#restore previous instance
if saved_shell_instance is not None:
cls = type(saved_shell_instance)
cls.clear_instance()
for subclass in cls._walk_mro():
subclass._instance = saved_shell_instance
if ps1 is not None:
sys.ps1 = ps1
sys.ps2 = ps2
示例12: ipython
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def ipython(user_ns=None):
ipydir = os.path.join(cache_dir, 'ipython')
os.environ['IPYTHONDIR'] = ipydir
BANNER = ('Welcome to the interactive vise shell!\n')
from IPython.terminal.embed import InteractiveShellEmbed
from traitlets.config.loader import Config
from IPython.terminal.prompts import Prompts, Token
class CustomPrompt(Prompts):
def in_prompt_tokens(self, cli=None):
return [
(Token.Prompt, 'vise['),
(Token.PromptNum, str_version),
(Token.Prompt, ']> '),
]
def out_prompt_tokens(self):
return []
defns = {'os': os, 're': re, 'sys': sys}
defns.update(user_ns or {})
c = Config()
c.TerminalInteractiveShell.prompts_class = CustomPrompt
c.InteractiveShellApp.exec_lines = [
'from __future__ import division, absolute_import, unicode_literals, print_function',
]
c.TerminalInteractiveShell.confirm_exit = False
c.TerminalInteractiveShell.banner1 = BANNER
c.BaseIPythonApplication.ipython_dir = ipydir
c.InteractiveShell.separate_in = ''
c.InteractiveShell.separate_out = ''
c.InteractiveShell.separate_out2 = ''
ipshell = InteractiveShellEmbed.instance(config=c, user_ns=user_ns)
ipshell()
示例13: ip
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
def ip(banner1='', **kw):
shell = InteractiveShellEmbed.instance(banner1=banner1, **kw)
shell(header='', stack_depth=2)
示例14:
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
if 1: # initialize QApplication
from PyQt4 import QtGui
if woo.runtime.ipython_version()==10:
wooQApp=QtGui.QApplication(sys.argv)
elif useQtConsole:
from IPython.frontend.qt.console.qtconsoleapp import IPythonQtConsoleApp
wooQApp=IPythonQtConsoleApp()
wooQApp.initialize()
else:
# create an instance of InteractiveShell before the inputhook is created
# see http://stackoverflow.com/questions/9872517/how-to-embed-ipython-0-12-so-that-it-inherits-namespace-of-the-caller for details
# fixes http://gpu.doxos.eu/trac/ticket/40
try: from IPython.terminal.embed import InteractiveShellEmbed # IPython>=1.0
except ImportError: from IPython.frontend.terminal.embed import InteractiveShellEmbed # IPython<1.0
from IPython.config.configurable import MultipleInstanceError
try: ipshell=InteractiveShellEmbed.instance()
except MultipleInstanceError:
print 'Already running inside ipython, not embedding new instance.'
# keep the qapp object referenced, otherwise 0.11 will die with "QWidget: Must construct QApplication before a QPaintDevice
# see also http://ipython.org/ipython-doc/dev/interactive/qtconsole.html#qt-and-the-qtconsole
import IPython.lib.inputhook #guisupport
wooQApp=IPython.lib.inputhook.enable_gui(gui='qt4')
#from IPython.lib.guisupport import start_event_loop_qt4
#start_event_loop_qt4(wooQApp)
#try:
# wooQApp.setStyleSheet(open(woo.config.resourceDir+'/qmc2-black-0.10.qss').read())
#except IOError: pass # stylesheet not readable or whatever
if sys.platform=='win32':
# don't use ugly windows theme, try something else
示例15: mapping
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import instance [as 别名]
parser.add_argument('-m', '--swarm-mappings', dest='swarm_mappings', metavar='SWARM_MAPPINGS', nargs='+', default=SWARM_MAPPINGS,
help='Use files SWARM_MAPPINGS to determine the SWARM input to IF mapping (default="{0}")'.format(SWARM_MAPPINGS))
args = parser.parse_args()
# Setup logging
logging.basicConfig()
logging.getLogger('katcp').setLevel(logging.CRITICAL)
logging.getLogger('').setLevel(logging.DEBUG if args.verbose else logging.INFO)
# Set up SWARM
swarm = Swarm(map_filenames=args.swarm_mappings)
# Commands added by Taco:
def takeNoiseData():
print "Enabling noise source - type takeSkyData() to undo this"
swarm.members_do(lambda i,m: m.dewalsh(False,False))
swarm.send_katcp_cmd("sma-astro-fstop-set","7.85","-12.15","-2.71359","0","0")
def takeSkyData():
swarm.set_walsh_patterns()
swarm.send_katcp_cmd("sma-astro-fstop-set","7.85","-12.15","-2.71359","1","1")
swarm.fringe_stopping(True)
# End of commands added by Taco
# Start the IPython embedded shell
ipshell = InteractiveShellEmbed.instance(config=cfg)
swarm_shell_magics = magics.SwarmShellMagics(ipshell, swarm)
ipshell.register_magics(swarm_shell_magics)
ipshell()