new PythonContextPythonContext sctx sThe class PythonContext represents a persistent Python execution environment that maintains its own global namespace. It allows you to evaluate Python expressions and statements across multiple calls, preserving defined variables and imports.
When a PythonContext object is created, the given string is executed as Python code within a new global context. Subsequent calls evaluate additional Python code in the same context, allowing variables and imports to persist.
Each evaluation returns a PythonObject representing the result of the final expression in the string, if any.
|
|
|
|
|
Here, the import from the Python math module is performed once during initialization. The variable x remains available in subsequent calls to the same PythonContext instance.
The object PythonContext is a self initializing type, with ancestor classes MutableHashTable < HashTable < Thing.
The source of this document is in Python/doc/context.m2:47:0.