0
In IDLE on mac, how do i go to the next line? When i press enter it runs the code but id like to execute more than one line.
2 odpowiedzi
+ 4
Don't have mac too, but at the prompt ( >>> ), you can execute multi-lines... there's two way of doing:
When an expression stand alone in a unique line ( means valid instruction runnable ), validate execute it, and you can type another one WITH KEEPING CONTEXT, so you can run/execute more than one line, but at this point, with big time lag due to time to type or even copy-paste ^^
Another way is provided by particularity of Python with defining blocks with indentation:
If you type an expression which need to become with a indented block of instructions, when you validate for new line, Python interpretor cannot yet execute it and may waiting for the next code to be typing by user... so Python ( Idle ) change the prompt sign ( from '>>>' to '. . .' ) to explicit that is waiting more code and will repeat that at each new line, until the user validate an empty line...
Well so, with all that stuff, we have a third way which open to us ;)
For executing more than one standalone instruction/expression at each line validation, we have to just define a block of code, what we could do by defining a function:
>>> def nexted_instructions():
. . . print("test")
. . . print("do others thing')
. . . print("how many you want")
. . . print("the only limit, is the lack of ease to edit/correct")
. . . print("by the way, Idle isn't design for that purpose ^^")
. . .
An then, excute it:
>>> nexted_intructions()
+ 1
You are using the shell window. You have to click File, and then new, to open an editing window with unlimited lines that you can save.