Blender snippets

execute console (run from script editor)

import bpy

from bpy import context
window = context.window_manager.windows[0]
screen = window.screen
for area in screen.areas:
    if area.type == 'CONSOLE':
        with context.temp_override(window=window, area=area):
            bpy.ops.console.execute()

console source code
Blender Python