Python Forum
TypeError: 'float' object is not callable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: 'float' object is not callable
#3
This cannot be:
def average(message):
    global average
When your python compiles your program it creates a variable named "average" that references a function. Later in the program you reassign that variable to be something else. Now "average" no longer references the function and you cannot call average(arguments).

This is a simpler example.
def average(*args):
    global average
    average = sum(args) / len(args)

print(average)
average(1, 2, 3, 4)
print(average)
average(1, 2, 3, 4)
Error:
<function average at 0x000001DD4E586160> 2.5 Traceback (most recent call last): File "c...", line 8, in <module> average(1, 2, 3, 4) TypeError: 'float' object is not callable
You can see in the output that "average" starts out referencing a function. The function is called and it reassigns average to be the average of 1, 2, 3, 4. Now there is no way to call the average function. The name (essentially what variables are in python) us being used to reference a float number, not a function.

To fix the problem you need to rename the function or the variable used to hold the float value.
TimofeyKolpakov likes this post
Reply


Messages In This Thread
RE: TypeError: 'float' object is not callable - by deanhystad - Dec-03-2022, 03:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 460 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 515 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 605 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 823 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 1,144 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,520 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Need help with 'str' object is not callable error. Fare 4 906 Jul-23-2023, 02:25 PM
Last Post: Fare
  TypeError: 'float' object is not callable #1 isdito2001 1 1,130 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: a bytes-like object is required ZeroX 13 4,496 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  'SSHClient' object is not callable 3lnyn0 1 1,230 Dec-15-2022, 03:40 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020