>>> import code
>>>
>>> interpreter = code.InteractiveInterpreter()
>>> myCode = code.compile_command('if True: print("IT\'S ONE!!")')
>>> interpreter.runcode(myCode)
TypeError: exec: arg 1 must be a string, file, or code object
It's obvious that interpreter.runcode accept string or code.
But myCode is None.
>>> myCode
>>>
According to code.compile_command documentation:
...
Returns a code object (the same as compile(source, filename, symbol))
if the command is complete and valid; None if the command is
incomplete; raises SyntaxError if the command is complete and contains
a syntax error, or raises OverflowError or ValueError if the command
contains an invalid literal.
If you pass a string to interpreter.runcode, it works.
>>> interpreter.runcode('if True: print("IT\'S ONE!!")')
IT'S ONE!!