[Q] ipython: Multiple commands on the same line and newlines

Terry Reedy tjreedy at udel.edu
Sat Apr 16 12:39:55 EDT 2011


On 4/16/2011 9:55 AM, Phil Winder wrote:
> Hi,
> I'm having a go at using ipython as a command prompt for data
> analysis. Coming from Matlab, I'm used to typing multiple commands on
> the same line then using the up arrow to go through my history.
> How can I write multiple python commands on the same line?

You can write multiple *simple* statements using ';'.

> E.g. "x = 0; while x<  10: x = x + 1;" returns an "invalid syntax"
> error on the 'e' in while.

All compound statements, like while, must start on own line.

> Also, how can I produce a new line, without it running the command?

Use an editor, as with IDLE, rather than a shell. Interactive mode runs 
*1* statement (including simple;simple) at a time.

> would have expected a ctrl-enter or shift-enter to produce the
> expected results.
> E.g. I want:
> "x = 0;<ctrl-enter>

This is one statement

> while x<  10:<ctrl-enter>
>      x = x + 1;<ctrl-enter>

This is another.

I can understanding wanting to rerun initialized loops with one enter, 
but you cannot. Sorry.

-- 
Terry Jan Reedy




More information about the Python-list mailing list