Run Python Code
Description
The Run Python Code task lets you interactively run Python® code or files. The task automatically generates MATLAB® code for your live script. For more information about Live Editor tasks generally, see Add Interactive Tasks to a Live Script.
Using this task, you can:
Write and execute Python code.
Execute code in Python files.
Return Python variables to the MATLAB workspace.
Pass MATLAB data to the Python code.
Specify command line arguments.
Open the Task
To add the Run Python Code task to a live script in the MATLAB Editor:
On the Live Editor tab, select Task > Run Python Code.
In a code block in the script, type a relevant keyword, such as
Python
orrun
. SelectRun Python Code
from the suggested command completions.
Parameters
Limitations
If you make a change to a Python class definition after the task has run, restart the Python interpreter or reload the Python module. For more information about reloading modified user-defined Python modules, see Call User-Defined Python Module.
Version History
Introduced in R2024a