public class PythonOutput
extends org.sagemath.singlecellserver.CommandReply
When Python produces output from code that has been compiled in with the 'single' flag to :func:`compile`, any expression that produces a value (such as ``1+1``) is passed to ``sys.displayhook``, which is a callable that can do with this value whatever it wants. The default behavior of ``sys.displayhook`` in the Python interactive prompt is to print to ``sys.stdout`` the :func:`repr` of the value as long as it is not ``None`` (which isn't printed at all). In our case, the kernel instantiates as ``sys.displayhook`` an object which has similar behavior, but which instead of printing to stdout, broadcasts these values as ``pyout`` messages for clients to display appropriately.
IPython's displayhook can handle multiple simultaneous formats depending on its configuration. The default pretty-printed repr text is always given with the ``data`` entry in this message. Any other formats are provided in the ``extra_formats`` list. Frontends are free to display any or all of these according to its capabilities. ``extra_formats`` list contains 3-tuples of an ID string, a type string, and the data. The ID is unique to the formatter implementation that created the data. Frontends will typically ignore the ID unless if it has requested a particular formatter. The type string tells the frontend how to interpret the data. It is often, but not always a MIME type. Frontends should ignore types that it does not understand. The data itself is any JSON object and depends on the format. It is often, but not always a string.
Message type: ``pyout``::
content = {
# The counter for this execution is also provided so that clients can
# display it, since IPython automatically creates variables called _N
# (for prompt N).
'execution_count' : int,
# The data dict contains key/value pairs, where the kids are MIME
# types and the values are the raw data of the representation in that
# format. The data dict must minimally contain the ``text/plain``
# MIME type which is used as a backup representation.
'data' : dict,
}
Modifier and Type | Method and Description |
---|---|
java.lang.String |
get()
Return a textual representation of the output
|
java.lang.String |
get(java.lang.String encoding)
Get the output
|
java.util.Iterator<?> |
getEncodings()
Get an iterator for the possible encodings.
|
java.lang.String |
toString() |
public java.lang.String toString()
toString
in class org.sagemath.singlecellserver.Command
public java.util.Iterator<?> getEncodings()
public java.lang.String get(java.lang.String encoding) throws org.json.JSONException
encoding
- Which of possibly multiple representations to returnorg.json.JSONException
public java.lang.String get()