本文整理汇总了Python中IPython.utils.io.stdout方法的典型用法代码示例。如果您正苦于以下问题:Python io.stdout方法的具体用法?Python io.stdout怎么用?Python io.stdout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.utils.io
的用法示例。
在下文中一共展示了io.stdout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_all
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def show_all(self):
"""Show entire demo on screen, block by block"""
fname = self.title
title = self.title
nblocks = self.nblocks
silent = self._silent
marquee = self.marquee
for index,block in enumerate(self.src_blocks_colored):
if silent[index]:
print(marquee('<%s> SILENT block # %s (%s remaining)' %
(title,index,nblocks-index-1)), file=io.stdout)
else:
print(marquee('<%s> block # %s (%s remaining)' %
(title,index,nblocks-index-1)), file=io.stdout)
print(block, end=' ', file=io.stdout)
sys.stdout.flush()
示例2: system_piped
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def system_piped(self, cmd):
"""Call the given cmd in a subprocess, piping stdout/err
Parameters
----------
cmd : str
Command to execute (can not end in '&', as background processes are
not supported. Should not be a command that expects input
other than simple text.
"""
if cmd.rstrip().endswith('&'):
# this is *far* from a rigorous test
# We do not support backgrounding processes because we either use
# pexpect or pipes to read from. Users can always just call
# os.system() or use ip.system=ip.system_raw
# if they really want a background process.
raise OSError("Background processes not supported.")
# we explicitly do NOT return the subprocess status code, because
# a non-None value would trigger :func:`sys.displayhook` calls.
# Instead, we store the exit_code in user_ns.
self.user_ns['_exit_code'] = system(self.var_expand(cmd, depth=1))
示例3: pdef
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def pdef(self, obj, oname=''):
"""Print the call signature for any callable object.
If the object is a class, print the constructor information."""
if not callable(obj):
print('Object is not callable.')
return
header = ''
if inspect.isclass(obj):
header = self.__head('Class constructor information:\n')
obj = obj.__init__
elif (not py3compat.PY3) and type(obj) is types.InstanceType:
obj = obj.__call__
output = self._getdef(obj,oname)
if output is None:
self.noinfo('definition header',oname)
else:
print(header,self.format(output), end=' ', file=io.stdout)
# In Python 3, all classes are new-style, so they all have __init__.
示例4: page_dumb
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def page_dumb(strng, start=0, screen_lines=25):
"""Very dumb 'pager' in Python, for when nothing else works.
Only moves forward, same interface as page(), except for pager_cmd and
mode."""
out_ln = strng.splitlines()[start:]
screens = chop(out_ln,screen_lines-1)
if len(screens) == 1:
print(os.linesep.join(screens[0]), file=io.stdout)
else:
last_escape = ""
for scr in screens[0:-1]:
hunk = os.linesep.join(scr)
print(last_escape + hunk, file=io.stdout)
if not page_more():
return
esc_list = esc_re.findall(hunk)
if len(esc_list) > 0:
last_escape = esc_list[-1]
print(last_escape + os.linesep.join(screens[-1]), file=io.stdout)
示例5: __init__
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def __init__(self, color_scheme='NoColor', call_pdb=False, ostream=None):
# Whether to call the interactive pdb debugger after printing
# tracebacks or not
self.call_pdb = call_pdb
# Output stream to write to. Note that we store the original value in
# a private attribute and then make the public ostream a property, so
# that we can delay accessing io.stdout until runtime. The way
# things are written now, the io.stdout object is dynamically managed
# so a reference to it should NEVER be stored statically. This
# property approach confines this detail to a single location, and all
# subclasses can simply access self.ostream for writing.
self._ostream = ostream
# Create color table
self.color_scheme_table = exception_colors()
self.set_colors(color_scheme)
self.old_scheme = color_scheme # save initial value for toggles
if call_pdb:
self.pdb = debugger.Pdb(self.color_scheme_table.active_scheme_name)
else:
self.pdb = None
示例6: process_input_line
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def process_input_line(self, line, store_history=True):
"""process the input, capturing stdout"""
stdout = sys.stdout
splitter = self.IP.input_splitter
try:
sys.stdout = self.cout
splitter.push(line)
more = splitter.push_accepts_more()
if not more:
try:
source_raw = splitter.source_raw_reset()[1]
except:
# recent ipython #4504
source_raw = splitter.raw_reset()
self.IP.run_cell(source_raw, store_history=store_history)
finally:
sys.stdout = stdout
示例7: process_input_line
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def process_input_line(self, line, store_history=True):
"""process the input, capturing stdout"""
#print "input='%s'"%self.input
stdout = sys.stdout
splitter = self.IP.input_splitter
try:
sys.stdout = self.cout
splitter.push(line)
more = splitter.push_accepts_more()
if not more:
source_raw = splitter.source_raw_reset()[1]
self.IP.run_cell(source_raw, store_history=store_history)
finally:
sys.stdout = stdout
示例8: _get_index
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def _get_index(self,index):
"""Get the current block index, validating and checking status.
Returns None if the demo is finished"""
if index is None:
if self.finished:
print('Demo finished. Use <demo_name>.reset() if you want to rerun it.', file=io.stdout)
return None
index = self.block_index
else:
self._validate_index(index)
return index
示例9: handle_image_stream
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def handle_image_stream(self, data, mime):
raw = base64.decodestring(data[mime].encode('ascii'))
imageformat = self._imagemime[mime]
fmt = dict(format=imageformat)
args = [s.format(**fmt) for s in self.stream_image_handler]
with open(os.devnull, 'w') as devnull:
proc = subprocess.Popen(
args, stdin=subprocess.PIPE,
stdout=devnull, stderr=devnull)
proc.communicate(raw)
示例10: handle_image_tempfile
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def handle_image_tempfile(self, data, mime):
raw = base64.decodestring(data[mime].encode('ascii'))
imageformat = self._imagemime[mime]
filename = 'tmp.{0}'.format(imageformat)
with nested(NamedFileInTemporaryDirectory(filename),
open(os.devnull, 'w')) as (f, devnull):
f.write(raw)
f.flush()
fmt = dict(file=f.name, format=imageformat)
args = [s.format(**fmt) for s in self.tempfile_image_handler]
subprocess.call(args, stdout=devnull, stderr=devnull)
示例11: get_ipython
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def get_ipython():
# This will get replaced by the real thing once we start IPython below
return start_ipython()
# A couple of methods to override those in the running IPython to interact
# better with doctest (doctest captures on raw stdout, so we need to direct
# various types of output there otherwise it will miss them).
示例12: xsys
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def xsys(self, cmd):
"""Replace the default system call with a capturing one for doctest.
"""
# We use getoutput, but we need to strip it because pexpect captures
# the trailing newline differently from commands.getoutput
print(self.getoutput(cmd, split=False, depth=1).rstrip(), end='', file=sys.stdout)
sys.stdout.flush()
示例13: _showtraceback
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def _showtraceback(self, etype, evalue, stb):
"""Print the traceback purely on stdout for doctest to capture it.
"""
print(self.InteractiveTB.stb2text(stb), file=sys.stdout)
示例14: clear_output
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def clear_output(stdout=True, stderr=True, other=True):
"""Clear the output of the current cell receiving output.
Optionally, each of stdout/stderr or other non-stream data (e.g. anything
produced by display()) can be excluded from the clear event.
By default, everything is cleared.
Parameters
----------
stdout : bool [default: True]
Whether to clear stdout.
stderr : bool [default: True]
Whether to clear stderr.
other : bool [default: True]
Whether to clear everything else that is not stdout/stderr
(e.g. figures,images,HTML, any result of display()).
"""
from IPython.core.interactiveshell import InteractiveShell
if InteractiveShell.initialized():
InteractiveShell.instance().display_pub.clear_output(
stdout=stdout, stderr=stderr, other=other,
)
else:
from IPython.utils import io
if stdout:
print('\033[2K\r', file=io.stdout, end='')
io.stdout.flush()
if stderr:
print('\033[2K\r', file=io.stderr, end='')
io.stderr.flush()
示例15: write_output_prompt
# 需要导入模块: from IPython.utils import io [as 别名]
# 或者: from IPython.utils.io import stdout [as 别名]
def write_output_prompt(self):
"""Write the output prompt.
The default implementation simply writes the prompt to
``io.stdout``.
"""
# Use write, not print which adds an extra space.
io.stdout.write(self.shell.separate_out)
outprompt = self.shell.prompt_manager.render('out')
if self.do_full_cache:
io.stdout.write(outprompt)