Unify exec python

Combines the two implementations of "execute_python_code_in_main_module". And some follow-on cleanup.
I suggest using "not" instead of "!". It does the same thing, but less prone for oversights and more readable same goes for "&&" and "||", for which I suggest using "and" and "or", respectively.