◐ Shell
clean mode source ↗

Message 98056 - Python tracker

The code.InteractiveConsole() is useful to emulate a python console.  However, any code currently "push"ed to it must be single statements.  This is because it passes the ´single´ symbol mode to the underlying compile function.
This patch allows the caller of InteractiveConsole.push to specify a different mode, e.g. ´exec´.  This is useful if one wants to paste entire code snippets into the console.  Without it, pasting the following:
'if True:\n  print 1\nprint 2' Won't run.  pushing such multiline code snippets with an additional 'exec' argument will allow it to work.
Patch included.