QtConsole Multiline Editing
Console input is usually one line, but real Python needs multiline constructs: function bodies, with blocks, long comprehensions. QtConsole supports proper multiline editing so you can write, edit, and rerun blocks without escaping the window.
Entering Multiline Mode
When you type a statement that is syntactically incomplete - an open def, if, for, with, or a trailing colon/backslash - the prompt switches to the continuation prompt (...), and Enter inserts a newline instead of submitting:
def fib(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
return a
print(fib(10)) # 55
Editing Within the Block
- Arrow keys move within the multiline buffer; standard editing keys work as in a normal text field.
- Ctrl+Enter submits the block; Enter on an incomplete line just adds a newline.
- Ctrl+C on an empty line cancels the block without submitting.
Pasting Multiline Code
Pasting a multi-line snippet enters the lines into the buffer; the console submits only when the block is complete. This makes it easy to paste a function from an editor and run it in place.
Triple-Quoted Strings
sql = '''
SELECT id, name
FROM users
WHERE active = 1
'''
print(sql.strip())
The console tracks triple-quoted strings too: Enter inside them continues the string rather than executing.
Tips
- For interactive loops, keep blocks short; a 40-line pasted function is easier to debug as a file run with %run.
- Use %paste to grab text from the clipboard as a block without manual editing.
- Re-running the last block: the console keeps recent inputs; Up-arrow recalls the previous submission.
Summary
QtConsole handles multiline input natively: incomplete statements (def, if, with, open brackets) switch to the ... continuation prompt, Enter adds newlines, and Ctrl+Enter submits. Paste blocks and triple-quoted strings behave correctly, and %paste plus history recall make the console a comfortable place for multi-line Python.