2

There are a number of questions about how to force EXECUTE instead of newline in ipython. But I need the opposite. Consider:

In [9]: import sqlalchemy sqlalchemy.__version__
  File "<ipython-input-9-84bd5002c701>", line 1
    import sqlalchemy sqlalchemy.__version__
                               ^
SyntaxError: invalid syntax

We can see that there should be two lines: ( 1 ) the import and ( 2 ) the __version__ invocation. Whatever I try I can not separate the two pieces.

One of the suggestions was ctl-v ctl-j: that simply did an EXECUTE again.

Another suggestion was Use %edit {tag} Adding line breaks in ipython : That gave an even more interesting behavior:

n [12]: %edit _i9
Editing... done. Executing edited code...
Out[12]: 'import sqlalchemy \nsqlalchemy.__version__ \n'

So notice: the (vi) editor did its job but then ipython simply converted the newlines to \n and did not interpret the newlines instead it concatenated them

So what key combination will get us the newline here?

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
  • I don't think you can. That requires both executing the first line, and starting the next with extra stuff. Sometimes it works to put a `;` between commands, but not in this case. I'd just delete or cut the `version` stuff, and reenter it after the import. – hpaulj Jun 17 '17 at 16:45

1 Answers1

2

Pressing Ctrl+q Ctrl-j should do the trick. Check this answer here.

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
gmagno
  • 1,770
  • 1
  • 19
  • 40