##// END OF EJS Templates
Add -q option (suppress print upon creation) to %macro...
Add -q option (suppress print upon creation) to %macro Macros are very, very useful and "Matlab" like (as well as other similar math computing environs). Often I (or my students) use a macro to load long complex code from a url -- e.g., large data sets, simulated data, preprocessing of data, special plotting commands, grading routines... Currently, this requires defining the macro at the end of the notebook so when the "print upon creation" occurs it doesn't overwhelm the notebook (except at the end). The -q option suppresses the print contents upon creation. Example with a Matplotlib example: In[1]: %macro tmp http://matplotlib.org/mpl_examples/api/date_demo.py Macro `tmp` created. To execute, type its name (without quotes). === Macro contents: === """ Show how to make date plots in matplotlib using date tick locators and formatters. See major_minor_demo1.py for more information on controlling major and minor ticks ... In[2]: %macro -q tmp2 http://matplotlib.org/mpl_examples/api/date_demo.py (nothing) Perhaps, though, the first line should print -- e.g., Macro `tmp` created. To execute, type its name (without quotes). In the docstraing, I also fixed a typo (an "as" that should be an "at") and clarified how to produce an example output.

File last commit:

r9372:37f32253
r10962:f96aac3a
Show More
payloadpage.py
96 lines | 2.9 KiB | text/x-python | PythonLexer
# encoding: utf-8
"""
A payload based version of page.
Authors:
* Brian Granger
* Fernando Perez
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Third-party
try:
from docutils.core import publish_string
except ImportError:
# html paging won't be available, but we don't raise any errors. It's a
# purely optional feature.
pass
# Our own
from IPython.core.interactiveshell import InteractiveShell
#-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
def page(strng, start=0, screen_lines=0, pager_cmd=None,
html=None, auto_html=False):
"""Print a string, piping through a pager.
This version ignores the screen_lines and pager_cmd arguments and uses
IPython's payload system instead.
Parameters
----------
strng : str
Text to page.
start : int
Starting line at which to place the display.
html : str, optional
If given, an html string to send as well.
auto_html : bool, optional
If true, the input string is assumed to be valid reStructuredText and is
converted to HTML with docutils. Note that if docutils is not found,
this option is silently ignored.
Notes
-----
Only one of the ``html`` and ``auto_html`` options can be given, not
both.
"""
# Some routines may auto-compute start offsets incorrectly and pass a
# negative value. Offset to 0 for robustness.
start = max(0, start)
shell = InteractiveShell.instance()
if auto_html:
try:
# These defaults ensure user configuration variables for docutils
# are not loaded, only our config is used here.
defaults = {'file_insertion_enabled': 0,
'raw_enabled': 0,
'_disable_config': 1}
html = publish_string(strng, writer_name='html',
settings_overrides=defaults)
except:
pass
payload = dict(
source='IPython.kernel.zmq.page.page',
text=strng,
html=html,
start_line_number=start
)
shell.payload_manager.write_payload(payload)
def install_payload_page():
"""Install this version of page as IPython.core.page.page."""
from IPython.core import page as corepage
corepage.page = page