I want to export the messages that appear on the Console Python (for example this below) using a script:
But I can't find a way to store it in a txt file. Any suggestion?
I want to export the messages that appear on the Console Python (for example this below) using a script:
But I can't find a way to store it in a txt file. Any suggestion?
This is a really horrible way of finding the right widget, I can almost guarantee there is a more elegant way (suggestions welcome), but nonetheless:
cons = iface.mainWindow().findChild(QDockWidget, 'PythonConsole')
children = cons.children()
pc = children[-1] # console.console.PythonConsole
pcw = pc.children()[0] # console.console.PythonConsoleWidget
shell = pcw.shellOutWidget
scin = shell.children()[1] # console.console_output.ShellOutputScintilla
contents = scin.text() # console text
write log to file
with open('console_log.txt', 'w+') as logfile:
logfile.write(contents)
"AttributeError: 'QSplitter' object has no attribute 'shellOutWidget'"– Taras Dec 09 '23 at 08:52console.console.PythonConsoleWidge^_^ – Taras Dec 09 '23 at 09:09if isinstance()rather than by indexing. I thought that might causes issues... – Matt Dec 09 '23 at 09:20