[Q] ipython: Multiple commands on the same line and newlines
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; while x < 10: x = x + 1; " It seems to work automatically for the "while xxx:", but combinations of keys+enter do not work for "normal" lines. Cheers, Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: ipython: Multiple commands on the same line and newlines
On Apr 16, 5:29 pm, Andrea Crotti wrote: > Phil Winder 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; > > while x < 10: > > x = x + 1; > > " > > 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 Yes, that does not produce an error, but it does not "work". Please refer to my first post. Try the first code, you will get a syntax error. Placing things on one line makes for easy history scrollback. In your version you will have 2 lines of history for the x = 0 term and the while ... term. I don't want to have to press up twice, especially when the code was in the distant past! Also cpaste might be ok for scripting, but it looks too clumsy to use at the command line. Cheers, Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: ipython: Multiple commands on the same line and newlines
On Apr 17, 1:11 pm, Andrea Crotti wrote: > Phil Winder writes: > > Yes, that does not produce an error, but it does not "work". Please > > refer to my first post. Try the first code, you will get a syntax > > error. Placing things on one line makes for easy history scrollback. > > In your version you will have 2 lines of history for the x = 0 term > > and the while ... term. I don't want to have to press up twice, > > especially when the code was in the distant past! Also cpaste might be > > ok for scripting, but it looks too clumsy to use at the command line. > > > Cheers, > > Phil > > Well I guess that's the way it is with the interpreter.. > But I don't see the sense in doing everything from there, just write the > code to a file and use %edit from ipython to change and run it, it's > quite nice and easy too. Ok, thanks all. It's a little disappointing, but I guess that you always have to work in a different way when you move to a new language. Andrea's %edit method is probably the best compromise, but this now means that I will have to learn all the (obscure) shortcuts for vi! Cheers, Phil -- http://mail.python.org/mailman/listinfo/python-list