Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
learning decorators
#1
hi,

I am learning decorators and trying to run this code but when i run it it says following error:
Error:
Traceback (most recent call last): File "D:\Learnpython\hard way python\decoratorss.py", line 138, in <module> var(**d) File "D:\Learnpython\hard way python\decoratorss.py", line 131, in wrapper return anys(*args, **kwargs) TypeError: 'list' object is not callable
this is my code:
def main(anys):
    def wrapper(*args, **kwargs):
        for k,v in kwargs.items():
            print(f"Key is {k} and value is {v}")
            return anys(*args, **kwargs)
    return wrapper

def getsquare(n):
    return [i**2 for i in range(n)]
var = main(getsquare(100))
d = {"d":1, "c":2, "f":3}
var(**d)
can anybody please explain what am i doing wrong
Reply
#2
getsquare() returns a list, which is passed to main(). It means that anys is a list instance and you cannot call anys().
Reply
#3
then how to solve it?
Reply
#4
(Aug-13-2018, 09:25 AM)Prince_Bhatia Wrote: then how to solve it?
What are you trying to achieve with this code? It is not at all obvious.
Reply
#5
i am trying to print the keywords from d and square of numbers in a list
Reply
#6
(Aug-13-2018, 09:25 AM)Prince_Bhatia Wrote: then how to solve it?
Is this homework?
Recommended Tutorials:
Reply
#7
No no.... I am a working individual. I am learning decortars online and thought to create a decorator that will take keywords from d and print a list also
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Decorators @ annotation drcl 3 395 Feb-24-2024, 06:12 AM
Last Post: Gribouillis
  Does @ at sign used for tother than decorators? ggpython000 1 542 Oct-12-2023, 09:08 AM
Last Post: buran
  Variable Scopes Decorators oclmedyb 6 2,736 Jan-15-2021, 02:13 PM
Last Post: oclmedyb
  Decorators and return statements JonEdward 2 1,890 Jul-24-2020, 05:02 PM
Last Post: JonEdward
  How to print cache from Decorators with Memoization OlgaM 2 2,069 Jan-29-2020, 05:06 PM
Last Post: OlgaM
  Python decorators. dodiko1d 0 8,269 Oct-13-2019, 10:23 AM
Last Post: dodiko1d
  Decorators yksingh1097 2 2,518 Aug-14-2018, 01:44 PM
Last Post: yksingh1097
  decorators within decorators mp3909 6 4,248 Apr-02-2018, 09:47 AM
Last Post: hf8bm
  decorators mp3909 9 5,597 Mar-25-2018, 05:28 PM
Last Post: mp3909

Forum Jump:

User Panel Messages

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