Xbasic

xbasic_execute_python Function

Syntax

dim result as P = xbasic_execute_python(pythonScript as C)

Arguments

pythonScriptCharacter

The Python script to execute.

Returns

resultPointer

Returns an object with the following properties:

errorLogical

.t. if an error occurs. Otherwise .f..

resultCharacter

If no error occurs, the output from the Python script

errorTextCharacter

If an error occurs, additional information about the error.

Description

Executes a Python script.

Discussion

The xbasic_execute_python() function runs a Python script. The Python code can execute Print() statements and the output generated by these Print() statements is returned in the result property.

dim pythonCode as c

pythonCode = <<%str%
def my_function():
    print("value1")
    print("value2")
my_function()
%str%

dim result as p

result = xbasic_execute_python(pythonCode)

if result.error = .f. then
    showvar(result.result)
else
    ' Error handling code here
end if

The Python code that you execute can use Python modules that you have installed.

See Also