Evaluates a Python expression and gets its string value.

 

   

Syntax
 

[C#]
string EvalString(string expr, in options)

 

Throws Exceptions ObjectDisposedException: Thrown when this PythonScope has been disposed of.
Throws Exceptions ArgumentNullException: Thrown when expr is null.
Throws Exceptions InvalidCastException: Thrown when the result is neither a string nor None.

 

   

Params
 
Name Description
expr A Python expression.
options Options for running Python code.
return The string value of the result, or null if the result is None.

 

   

Notes
 

Evaluates a Python expression and gets its string value.example: To get the version of Docling:.

 

   

Example
 

For example to get the version of Docling you might use code of the following form.

 

var options = new PythonOptions(); options.Initialize(PythonEnvironment.Current, null); using var rt = PythonEnvironment.Current.GetRuntime(); using var scope = rt.CreateScope(); rt.StdOutWriter = Console.Out; rt.StdErrWriter = Console.Error; rt.AutoInitializeRuntime(scope, null); var result = scope.EvalString("__import__('importlib.metadata', fromlist=['metadata']).version('docling')\n"); Console.WriteLine(result);