Pasting multiple lines into IDLE

后端 未结 3 661
情书的邮戳
情书的邮戳 2020-12-03 06:49

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

3条回答
  •  星月不相逢
    2020-12-03 07:29

    Probably not the most beautiful procedure, but this works:

    cmds = '''
    

    paste your commands, followed by ''':

    a = 1
    b = 2
    c = 3
    '''
    

    Then exec(cmds) will execute them.

    Or more directly,

    exec('''
    

    then paste your commands, followed by '''):

    a = 1
    b = 2
    c = 3
    ''')
    

    It's just a trick, maybe there's a more official, elegant way.

提交回复
热议问题