Commit 34af80e4 authored by Dave DeMarle's avatar Dave DeMarle Committed by Code Review
Browse files

Merge topic 'python-interactive-interpreter' into master

99e86323 Add RunStringWithConsoleLocals() to vtkPythonInteractiveInterpreter
parents 3531c085 99e86323
......@@ -182,6 +182,31 @@ bool vtkPythonInteractiveInterpreter::Push(const char* const code)
return ret_value;
int vtkPythonInteractiveInterpreter::RunStringWithConsoleLocals(const char* script)
// The implementation of this method is modeled after
// PyRun_SimpleStringFlags() found in Python's pythonrun.c
this->Internals->GetInteractiveConsole(); //ensure the console is initialized
PyObject* context = this->Internals->GetInteractiveConsoleLocalsPyObject();
PyObject* result = PyRun_String(const_cast<char*>(script), Py_file_input, context, context);
if (result == NULL)
return -1;
if (Py_FlushLine())
return 0;
void vtkPythonInteractiveInterpreter::Reset()
......@@ -60,6 +60,14 @@ public:
// code.InteractiveConsole().
void Reset();
// Description:
// Executes the given python source code using the context given by the
// locals() object used by this interactive console. This is similar to
// using vtkPythonInterpreter::RunSimpleString(), except that method will
// execute code in the context of the __main__ module. Returns 0 on success
// or -1 if an exception was raised.
int RunStringWithConsoleLocals(const char* script);
// Description:
// Provides access to the internal PyObject instances used for the
// code.InteractiveConsole() as well as the dictionary for the locals of the
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment