These are chat archives for ipython/ipython

Oct 2018
Oct 26 2018 14:09
$ ipython
Python 3.7.0 (default, Jun 29 2018, 20:14:27)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.0.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: def foo():
   ...:     x = 1

In [2]:
I typed a single newline at the end of the line that reads x = 1
More generally I can’t seem to define a function that has more than one line
What am I doing wrong ?
this is on a macos
$ uname -a
Darwin zag 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 21 20:07:39 PDT 2018; root:xnu-3789.73.14~1/RELEASE_X86_64 x86_64
Zachary Sailer
Oct 26 2018 16:02

@parmentelat You’re not doing anything wrong. There is a lot of discussion about how Enter should behave in IPython terminal (and lots of constraints). The default behavior seems to be—if the code can execute, then execute it. This behavior is customizable too, if you are willing to write some code in your configuration.

You can find more detail about this behavior here.

In the meantime, you can add a dummy line to your function (maybe return None) and move your cursor above that line to add code inside the function. Hitting enter between the function def line and the last line won’t execute the function. It’s not ideal, but its workable.