0

When I am building a function in python, using spyder, the function object is not working properly.

e.g.,

def first_order(y,t):
    tau=5

After introducing the 2nd line it automatically closes the function. How can I change this behavior?

It used to be like this

    def first_order(y,t):

>             tau=5 
    ...: (first Enter, creates a new line)
(second Enter, to close the function)
Manuel Oliveira
  • 527
  • 5
  • 19
  • please write an example of your problem and state the expected outcome – Glostas Nov 09 '18 at 09:50
  • It doesn't seem like you did what it said. Function definition works fine in spyder – user8408080 Nov 09 '18 at 09:59
  • your indentation is wrong – Glostas Nov 09 '18 at 10:01
  • Manuel, could you please tell me, does [the answer I've posted](https://stackoverflow.com/a/53223752/2749397) solve your problem? I ask because I'd prefer to remove it if it is not correct or, worse, misleading. Thank you. – gboffi Nov 09 '18 at 11:16
  • @user8408080 Manuel report is _mostly_ correct, they just had a wrong reason for the buggy behaviour. It's not Spyder in itself, nor the the Python interpreter, but it's an issue with the interactive console used by Spyder, i.e., IPython. See [my answer](https://stackoverflow.com/a/53223752/2749397) below for details – gboffi Nov 09 '18 at 11:43

2 Answers2

0

Spyder uses IPython in its interactive console. What you report is a bug in IPython 7.0, so the cleanest solution is to upgrade to IPython 7.1.

As a stop gap measure, if your platform doesn't provide 7.1 yet, you can use the key-chord Ctrl-o (instead of Return) to open a new line below the second line of the function definition and move there using the cursor key — after this maneuver the situation will be normal for the rest of the function definition.

Update

I knew that Spyder uses IPython, I didn't knew that it uses it via the qtconsole and the bug I described was still not fixed in 7.1 qtconsole (thank you Carlos Cordoba for pointing out).

The reason why OP has a problem still stands as valid, I fear that we have to wait 7.2 to have a fix for the qtconsole because the ad interim solution that I've described doesn't work in qtconsole

gboffi
  • 22,939
  • 8
  • 54
  • 85
  • (*Spyder maintainer here*) This is still an issue in IPython 7.1, so I think we need to change something in qtconsole to fix this. – Carlos Cordoba Nov 09 '18 at 15:53
  • @CarlosCordoba AH! Spyder uses qtconsole... The issue was solved in IPython 7.1 _"plain"_ console. I'll edit my answer because I feel it is still relevant re the diagnosis of the problem, if not for its resolution. Thank you for pointing out my mistake. – gboffi Nov 09 '18 at 20:29
0

(Spyder maintainer here) This is a bug in the Qtconsole package and it'll be fixed in its 4.4.3 version, to be released today.

Carlos Cordoba
  • 33,273
  • 10
  • 95
  • 124