The py4j.protocol module defines most of the types, functions, and characters used in the Py4J protocol. It does not need to be explicitly used by clients of Py4J because it is automatically loaded by the java_gateway module and the java_collections module.
Exception raised when an exception occurs in the client code.
The exception instance that was thrown on the Java side can be accessed with Py4JJavaError.java_exception.
str(py4j_java_error) returns the error message and the stack trace available on the Java side (similar to printStackTrace()).
Exception raised when a network error occurs with Py4J.
The following functions can be used to extend Py4J (e.g., to create new commands):
Replaces new line characters by a backslash followed by a n.
Backslashes are also escaped by another backslash.
Parameters: | original – the string to escape |
---|---|
Return type: | an escaped string |
Replaces escaped characters by unescaped characters.
For example, double backslashes are replaced by a single backslash.
Parameters: | escaped – the escaped string |
---|---|
Return type: | the original string |
Converts a Python object into a string representation respecting the Py4J protocol.
For example, the integer 1 is converted to u’i1’
Parameters: | parameter – the object to convert |
---|---|
Return type: | the string representing the command part |
Converts an answer received from the Java gateway into a Python object.
For example, string representation of integers are converted to Python integer, string representation of objects are converted to JavaObject instances, etc.
Parameters: |
|
---|
Registers an output converter to the list of global output converters.
Parameters: |
|
---|
Registers an input converter to the list of global input converters.
When initialized with auto_convert=True, a JavaGateway will use the input converters on any parameter that is not a JavaObject or basestring instance.
Parameters: | converter – A converter that declares the methods can_convert(object) and convert(object,gateway_client). |
---|