sys.displayhook - python examples

Here are the examples of the python api sys.displayhook taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

28 Examples 7

5 View Complete Implementation : test_sys.py
Copyright GNU General Public License v3.0
Author : Acmesec
    def test_lost_displayhook(self):
        olddisplayhook = sys.displayhook
        del sys.displayhook
        code = compile("42", "<string>", "single")
        self.astertRaises(RuntimeError, eval, code)
        sys.displayhook = olddisplayhook

5 View Complete Implementation : test_sys.py
Copyright GNU General Public License v3.0
Author : Acmesec
    def test_custom_displayhook(self):
        olddisplayhook = sys.displayhook
        def baddisplayhook(obj):
            raise ValueError
        sys.displayhook = baddisplayhook
        code = compile("42", "<string>", "single")
        self.astertRaises(ValueError, eval, code)
        sys.displayhook = olddisplayhook

5 View Complete Implementation : manhole.py
Copyright MIT License
Author : adde88
    def runcode(self, *a, **kw):
        orighook, sys.displayhook = sys.displayhook, self.displayhook
        try:
            origout, sys.stdout = sys.stdout, FileWrapper(self.handler)
            try:
                code.InteractiveInterpreter.runcode(self, *a, **kw)
            finally:
                sys.stdout = origout
        finally:
            sys.displayhook = orighook

5 View Complete Implementation : python_console.py
Copyright GNU General Public License v3.0
Author : jabbercat
@contextlib.contextmanager
def enable_pprint(width):
    prev = sys.displayhook

    def pprint_displayhook(v):
        if v is None:
            return
        pprint.pprint(v, width=width)

    sys.displayhook = pprint_displayhook

    yield
    sys.displayhook = prev

3 View Complete Implementation : recipe-364192.py
Copyright MIT License
Author : ActiveState
def toggle_ShortForm():
    """Toggle the shortening of output."""
    if sys.displayhook==shortForm:
        off()
    else:
        on()

3 View Complete Implementation : test_sys.py
Copyright MIT License
Author : emilyemorehouse
    def test_custom_displayhook(self):

        def baddisplayhook(obj):
            raise ValueError
        sys.displayhook = baddisplayhook
        code = compile('42', '<string>', 'single')
        self.astertRaises(ValueError, eval, code)

3 View Complete Implementation : printing.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def _init_python_printing(stringify_func, **settings):
    """Setup printing in Python interactive session. """
    import sys
    from sympy.core.compatibility import builtins

    def _displayhook(arg):
        """Python's pretty-printer display hook.

           This function was adapted from:

            http://www.python.org/dev/peps/pep-0217/

        """
        if arg is not None:
            builtins._ = None
            print(stringify_func(arg, **settings))
            builtins._ = arg

    sys.displayhook = _displayhook

3 View Complete Implementation : execute.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : jupytercalpoly
    def __enter__(self):
        self.sys_displayhook = sys.displayhook

        displayhook = sys.displayhook = self.capture_func

        return displayhook

3 View Complete Implementation : printing.py
Copyright MIT License
Author : ktraunmueller
def _init_python_printing(stringify_func):
    """Setup printing in Python interactive session. """
    import sys
    from sympy.core.compatibility import builtins

    def _displayhook(arg):
        """Python's pretty-printer display hook.

           This function was adapted from:

            http://www.python.org/dev/peps/pep-0217/

        """
        if arg is not None:
            builtins._ = None
            print(stringify_func(arg))
            builtins._ = arg

    sys.displayhook = _displayhook

2 View Complete Implementation : display_trap.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
    def set(self):
        """Set the hook."""
        if sys.displayhook is not self.hook:
            self.old_hook = sys.displayhook
            sys.displayhook = self.hook