readline.get_history_item(n)
でできる。
for i in range(readline.get_current_history_length()): print(readline.get_history_item(i+1))
Command history in interactive Python interpreter | by Amos Shapira | Medium
インタラクティブシェルのセッションを開始していろいろ実行した後から↑を実行しても、過去の履歴に遡って取得できる。