Pasting multiple lines into IDLE

Viewed 23170

Is there a way to paste a block of code into IDLE? Pasting line by line works, but sometimes I'd like to paste many lines at once. When I try, IDLE reads the first line and ignores the rest.

>>> a = 1
b = 2
c = 3

>>> 
>>> a
1
>>> b

Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    b
NameError: name 'b' is not defined
4 Answers

IdleX provides the PastePyShell.py extension for IDLE which allows pasting of multiple lines into the shell for execution.

Based on the answer of RedGlyph, but with some automation using AutoHotKey:

; python Idle shell
#IfWinActive ahk_exe pythonw.exe

^+x::  ; Idle - multiple commands paste 
SoundBeep,1700, 150
send, ^{end}
var1 = cmds = '''
var2 := clipboard
var3 = %var1%%var2%
var4 = %var3%'''
msgbox,,, %var4%,2
clipboard = %var4%
send, ^{vk0x56}   ;send, ^v
send, {enter}
sleep, 1000
send, exec(cmds)
return

You need to install AutoHotKey to make this work. After Installing AutoHotKey, the above code sample must be saved in a file with extension AHK (e.g. Idle.ahk), and should be running always to enable the shortcut: Ctrl+Shift+x to make the string manipulation for you.

Related