4
votes

I'm trying to use the max function in Python 3,6:

print('Maximum is:', max(1, 3, 2, 5, 4))

And the result is

  File "E:/ProgramyRobione/untitled1.py", line 2, in <module>
    print('Maximum is:', max(1, 3, 2, 5, 4))

TypeError: 'int' object is not callable

I'm using Spyder and that line is all that code should do.

1
Evidently you've assigned max = somewhere; don't do that. - jonrsharpe
@dkato actually they don't - docs.python.org/3/library/functions.html#max. Also it's helpful to describe what you're actually doing with that - "pass a list or tuple of numbers", to relate the syntax to something the OP can search for. - jonrsharpe
It is a builtin but you've got something that isn't - can you show the first line of your code? - Jon Clements♦
It doesn't have to be an exotic Python interpreter. This is actually very easy to recreate if you defined max = some_int in the iPython console of Spyder and then try to run your script since there is a global namespace. If you're using an IDE which supports this, try restarting the console (usually ctrl + .) - roganjosh
@dkato btw - you can delete your own comments... just hover over them and you'll get an (x) at the end of it - click that and it's gone - no need to edit it to say it's deleted :) - Jon Clements♦

1 Answers

9
votes

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.