Here are two variations on the answers given by Patan and sambler that some may prefer.
Variant of Sambler's answer
If you care about in-Python-console logging, but not availability/persistence of variables, then this approach is a slightly simpler alternative to sambler's answer: (run this in the Python console)
Variant of Patam's answer
If you care about in-Python-console logging, but not availability/persistence of variables, then this approach is an alternative to Patam's answer: (use this as your in-Blender "launcher" script)
# this code block will redirect calls to print() to show up in the Python-console panel
def write(self, text):
sys.__stdout__.write(text) # also send to standard-output (can comment this out)
if text != '\n': # ignore extra stdout.write('\n') call at end of each print()
for line in text.replace('\t', ' ').split('\n'):
for area in bpy.context.screen.areas:
if area.type == 'CONSOLE':
sys.stdout = StdOutOverride()
filename = "/full/path/to/myscript.py"
exec(compile(open(filename).read(), filename, 'exec'))
I prefer this last approach myself, as it lets you get logging in the Python console, while still being able to use the convenient "Play" button in the script-panel's toolbar. (and this way there's less conflict, in case variable-names in the script overlap with whatever code I may be iterating on in the Python console)