We're back after a server migration that caused effbot.org to fall over a bit harder than expected. Expect some glitches.

How can I execute arbitrary Python statements from C?

The highest-level function to do this is PyRun_SimpleString which takes a single string argument to be executed in the context of the __main__ module and returns 0 for success and -1 when an exception occurred (including SyntaxError). If you want more control, use PyRun_String; see the source for PyRun_SimpleString in Python/pythonrun.c.

CATEGORY: extending