Builtin Function Not Working with Spyder

Builtin function not working with Spyder

This is a bit of an iPython headshot that comes with Spyder. I've fallen foul of this when copy/pasting random bits of code from SO to test only to find really odd behaviour several days later - variables defined in the iPython console will also be in the script's global namespace indefinitely.

There's two things you can do:

  1. A hard restart of the Kernel (ctrl + .)
  2. Follow up on this feature request thread where it's now possible to clear the namespace automatically every time you run a script.

Python Str object is not callable in Spyder

You have overwritten the built-in str somewhere in your code.

>>> str = 'foo'   # overwriting the builtin `str`
>>> x = 5
>>> print str(x) # equivalent to 'foo'(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable

Simple input function gives spyder an internal problem

This bug has been reported on Github and is supposedly fixed. See https://github.com/spyder-ide/spyder/issues/17616

Instructions there are to upgrade to 5.3.0.

Spyder console not displaying function output

(Spyder maintainer here) You need to use a print if you want to see something printed in the console. In the example shown above, you need to change your code like this

print(type(13.4))

to see the result displayed in the console.

Strange module reload behavior in spyder or IPython

This is a feature in Spyder that is built on purpose to allow you to continue running from stop points, especially when considering longer run times to generate specific results, and also powers the variable explorer function.

There is a way around it though following the instructions in this answer to Clear all variables before each run or by restarting.

However, as pointed out by roganjosh, clearing the namespace is not necessarily better.

You can run a function that takes 10 mins to process data and return it to a global name, then just hash that function call out for every subsequent run and never have to incur the processing time again (until you wipe the namespace, that is).

If you want to only reset one or a group of variables, you can use reset_selective

%reset_selective [-f] regex


Related Topics



Leave a reply



Submit