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
See this other post: Python, writing multi line code in IDLE You can use an editor (File > New File), write your lines of code there and use F5
Probably not the most beautiful procedure, but this works:
paste your commands, followed by
'''
:Then
exec(cmds)
will execute them.Or more directly,
then paste your commands, followed by
''')
:It's just a trick, maybe there's a more official, elegant way.
IdleX provides the PastePyShell.py extension for IDLE which allows pasting of multiple lines into the shell for execution.