Method 1. Use the 'history-previous' key, which defaults to Alt-P ('history-next' is Alt-N, replace 'Alt' with 'Control' for Mac). It retrieves previous statements in the history list. (Some consoles, including that on Windows, only retrieve physical lines.) This is described in the IDLE Help document under Python Shell Window - Command History. Your example:
>>> class Car(object):
def __init__(self, model, year):
self.model=model
self.year=year
>>> a = 2
>>> class Car(object):
def __init__(self, model, year):
self._model=model
self._year=year
>>>
I retrieved the class definition by hitting Alt-P twice. After finishing editing, make sure to move the cursor to the end before hitting Enter
.
Method 2. Scroll back up, select the text you want copied (it need not be a complete statement), hit Enter
, and the selected text will be copied to the current input line.