MCPcopy Index your code
hub / github.com/python/cpython / displayhook

Function displayhook

Lib/idlelib/rpc.py:614–630  ·  view source on GitHub ↗

Override standard display hook to use non-locale encoding

(value)

Source from the content-addressed store, hash-verified

612# existing test code was removed at Rev 1.27 (r34098).
613
614def displayhook(value):
615 """Override standard display hook to use non-locale encoding"""
616 if value is None:
617 return
618 # Set '_' to None to avoid recursion
619 builtins._ = None
620 text = repr(value)
621 try:
622 sys.stdout.write(text)
623 except UnicodeEncodeError:
624 # let's use ascii while utf8-bmp codec doesn't present
625 encoding = 'ascii'
626 bytes = text.encode(encoding, 'backslashreplace')
627 text = bytes.decode(encoding, 'strict')
628 sys.stdout.write(text)
629 sys.stdout.write("\n")
630 builtins._ = value
631
632
633if __name__ == '__main__':

Callers

nothing calls this directly

Calls 3

writeMethod · 0.45
encodeMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…