本文整理汇总了Python中IPython.terminal.interactiveshell.TerminalInteractiveShell方法的典型用法代码示例。如果您正苦于以下问题:Python interactiveshell.TerminalInteractiveShell方法的具体用法?Python interactiveshell.TerminalInteractiveShell怎么用?Python interactiveshell.TerminalInteractiveShell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.terminal.interactiveshell
的用法示例。
在下文中一共展示了interactiveshell.TerminalInteractiveShell方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ipython_shell
# 需要导入模块: from IPython.terminal import interactiveshell [as 别名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 别名]
def ipython_shell(user_ns):
from IPython.terminal.ipapp import TerminalIPythonApp
from IPython.terminal.interactiveshell import TerminalInteractiveShell
class MyIPythonApp(TerminalIPythonApp):
def init_shell(self):
self.shell = TerminalInteractiveShell(
prompts_class=MyPrompt, highlighting_style='emacs',
display_banner=False, profile_dir=self.profile_dir,
ipython_dir=self.ipython_dir, banner1=get_banner(), banner2='')
self.shell.configurables.append(self)
app = MyIPythonApp.instance()
app.initialize()
app.shell.user_ns.update(user_ns)
sys.exit(app.start())
示例2: embed
# 需要导入模块: from IPython.terminal import interactiveshell [as 别名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 别名]
def embed(**kwargs):
"""Call this to embed IPython at the current point in your program.
The first invocation of this will create an :class:`InteractiveShellEmbed`
instance and then call it. Consecutive calls just call the already
created instance.
If you don't want the kernel to initialize the namespace
from the scope of the surrounding function,
and/or you want to load full IPython configuration,
you probably want `IPython.start_ipython()` instead.
Here is a simple example::
from IPython import embed
a = 10
b = 20
embed('First time')
c = 30
d = 40
embed
Full customization can be done by passing a :class:`Config` in as the
config argument.
"""
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
shell = InteractiveShellEmbed.instance(**kwargs)
shell(header=header, stack_depth=2, compile_flags=compile_flags)
示例3: init_alias
# 需要导入模块: from IPython.terminal import interactiveshell [as 别名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 别名]
def init_alias(self):
# InteractiveShell defines alias's we want, but TerminalInteractiveShell defines
# ones we don't. So don't use super and instead go right to InteractiveShell
InteractiveShell.init_alias(self)
#-------------------------------------------------------------------------
# Things related to exiting
#-------------------------------------------------------------------------
示例4: main
# 需要导入模块: from IPython.terminal import interactiveshell [as 别名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 别名]
def main():
url = sys.argv[1]
context['url'] = url
pkg = app.dispatch_url(url)
context['pkg'] = pkg
for item in pkg.to_dict().items():
print '{} = {}'.format(*item)
def prepare_readline():
import os
import readline
import atexit
readline.parse_and_bind('tab: complete')
histfile = os.path.expanduser("~/.daenerys_history")
try:
readline.read_history_file(histfile)
except IOError:
pass
def savehist(histfile):
readline.write_history_file(histfile)
atexit.register(savehist, histfile)
del atexit
try:
from IPython.terminal.interactiveshell import TerminalInteractiveShell
shell = TerminalInteractiveShell(user_ns=context)
shell.mainloop()
except ImportError:
import code
shell = code.InteractiveConsole(locals=context)
shell.runcode(prepare_readline.__code__)
shell.interact()
示例5: test_ipython_console
# 需要导入模块: from IPython.terminal import interactiveshell [as 别名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 别名]
def test_ipython_console(qtbot):
"""Test mock-creating a console from within ipython."""
def mock_get_ipython():
return TerminalInteractiveShell()
with mock.patch(
'napari._qt.qt_console.get_ipython', side_effect=mock_get_ipython
):
console = QtConsole()
qtbot.addWidget(console)
assert console.kernel_client is None
示例6: get_python_console
# 需要导入模块: from IPython.terminal import interactiveshell [as 别名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 别名]
def get_python_console(namespace=None):
"""
Return a interactive python console instance with caller's stack
"""
if namespace is None:
import inspect
frame = inspect.currentframe()
caller = frame.f_back
if not caller:
logging.error("can't find caller who start this console.")
caller = frame
namespace = dict(caller.f_globals)
namespace.update(caller.f_locals)
try:
from IPython.terminal.interactiveshell import TerminalInteractiveShell
shell = TerminalInteractiveShell(user_ns=namespace)
except ImportError:
try:
import readline
import rlcompleter
readline.set_completer(rlcompleter.Completer(namespace).complete)
readline.parse_and_bind("tab: complete")
except ImportError:
pass
import code
shell = code.InteractiveConsole(namespace)
shell._quit = False
def exit():
shell._quit = True
def readfunc(prompt=""):
if shell._quit:
raise EOFError
return six.moves.input(prompt)
# inject exit method
shell.ask_exit = exit
shell.raw_input = readfunc
return shell
示例7: interactive
# 需要导入模块: from IPython.terminal import interactiveshell [as 别名]
# 或者: from IPython.terminal.interactiveshell import TerminalInteractiveShell [as 别名]
def interactive(port=None, InterfaceClass=CanInterface, intro='', load_filename=None, can_baud=None):
global c
import atexit
c = InterfaceClass(port=port, load_filename=load_filename)
atexit.register(cleanupInteractiveAtExit)
if load_filename is None:
if can_baud != None:
c.setCanBaud(can_baud)
else:
c.setCanBaud(CAN_500KBPS)
gbls = globals()
lcls = locals()
try:
import IPython.Shell
ipsh = IPython.Shell.IPShell(argv=[''], user_ns=lcls, user_global_ns=gbls)
print intro
ipsh.mainloop(intro)
except ImportError, e:
try:
from IPython.terminal.interactiveshell import TerminalInteractiveShell
from IPython.terminal.ipapp import load_default_config
ipsh = TerminalInteractiveShell(config=load_default_config())
ipsh.user_global_ns.update(gbls)
ipsh.user_global_ns.update(lcls)
ipsh.autocall = 2 # don't require parenthesis around *everything*. be smart!
ipsh.mainloop(intro)
except ImportError, e:
try:
from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
ipsh = TerminalInteractiveShell()
ipsh.user_global_ns.update(gbls)
ipsh.user_global_ns.update(lcls)
ipsh.autocall = 2 # don't require parenthesis around *everything*. be smart!
ipsh.mainloop(intro)
except ImportError, e:
print e
shell = code.InteractiveConsole(gbls)
shell.interact(intro)