# Running a Python script with c++

**URL:** <https://forums.unrealengine.com/t/running-a-python-script-with-c/114117>\
**Category:** Pipeline & Plugins\
**Tags:** Datasmith, unreal-engine\
**Created:** [July 25, 2018, 1:55pm UTC](https://forums.unrealengine.com/t/running-a-python-script-with-c/114117 "2018-07-25T13:55:58Z")\
**Posts on this page:** 1\
**Page:** 2

<div class="post-metadata">

**Author:** ![mwojt-platige](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mwojt-platige](https://forums.unrealengine.com/u/mwojt-platige)\
**Post date:** [April 11, 2025, 6:34am UTC](https://forums.unrealengine.com/t/running-a-python-script-with-c/114117/21 "2025-04-11T06:34:12Z")

</div>

For executing more complex Python scripts, it’s better to construct a command using `FPythonCommandEx` struct and pass it to the exec function. For example:

```auto
FPythonCommandEx PythonCommand;
PythonCommand.Command = FString::Printf(
      TEXT("from my_module import MyClass; "\
      "my_class = MyClass(); "\
      "my_class.call_my_method()")
);
PythonCommand.ExecutionMode = EPythonCommandExecutionMode::ExecuteStatement;
PythonCommand.FileExecutionScope = EPythonFileExecutionScope::Public;
bool Result = IPythonScriptPlugin::Get()->ExecPythonCommandEx(PythonCommand);

```

[Previous page](https://forums.unrealengine.com/t/running-a-python-script-with-c/114117.md?page=1)
