Python Forum
TypeError: 'NoneType' object is not callable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: 'NoneType' object is not callable
#5
The site you get code from use plain HTML without even a <code> tag to display the code this is bad.
Usually if make a site where people post a lot of code,then have some kind of code box.
If look at source eg:
<span style="background-color:#ffffcc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cache[args] = result</span>
A overflow of &nbsp💥
So can get strange result if try to copy code,look like you have written the code over as there are typo's to.
The code work,here a cleaned up versions and i made a few changes.
import time

def memoize(func):
    cache = {}
    def wrapper(*args):
        if args not in cache:
            cache[args] = func(*args)
        return cache[args]
    return wrapper

def timed(func):
    def wrapper(*args):
        start = time.time()
        result = func(*args)
        end = time.time()
        elapsed_time = end - start
        print(f"Elapsed time: {elapsed_time:.6f} seconds")
        return result
    return wrapper

@memoize
@timed
def sum_of_odd_numbers(n):
    return sum(x for x in range(n) if x % 2 == 1)

print(sum_of_odd_numbers(10000000))
print(sum_of_odd_numbers(10000000))
Output:
Elapsed time: 0.759998 seconds 25000000000000 25000000000000
akbarza likes this post
Reply


Messages In This Thread
RE: TypeError: 'NoneType' object is not callable - by snippsat - Aug-24-2023, 05:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 462 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 582 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 792 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,475 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Need help with 'str' object is not callable error. Fare 4 890 Jul-23-2023, 02:25 PM
Last Post: Fare
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,613 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  TypeError: 'float' object is not callable #1 isdito2001 1 1,116 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  TypeError: a bytes-like object is required ZeroX 13 4,340 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  'SSHClient' object is not callable 3lnyn0 1 1,215 Dec-15-2022, 03:40 AM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,515 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov

Forum Jump:

User Panel Messages

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