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

Andrea Crotti andrea.crotti.0 at gmail.com
Sat Apr 16 12:29:20 EDT 2011


Phil Winder <philipwinder at gmail.com> writes:

> 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?
> E.g. "x = 0; while x < 10: x = x + 1;" returns an "invalid syntax"
> error on the 'e' in while.
>
> Also, how can I produce a new line, without it running the command? I
> would have expected a ctrl-enter or shift-enter to produce the
> expected results.
> E.g. I want:
> "x = 0; <ctrl-enter>
> while x < 10: <ctrl-enter>
>     x = x + 1; <ctrl-enter>
> " <enter to run>
> It seems to work automatically for the "while xxx:", but combinations
> of keys+enter do not work for "normal" lines.
>
> Cheers,
> Phil

Well when you do something like

while x < 10:

it doesn't execute anything, but goes to newline and waits for the rest.

for
x = 10

what's the difference for you if it gets evaluated before or after?
Anyway you can you also %cpaste if you want to write more code

Anyway to me this works perfectly:
In [1]: x = 0

In [2]: while x < 10: print x; x += 1
   ...: 
0
1
2
3
4
5
6
7
8
9




More information about the Python-list mailing list