-2

I'm trying to understand why I'm not only getting the func name back when running the code.

def smart_divide(func):
    def inner(a, b):
        print("I am going to", func, a, "and", b)
        if b == 0:
            print("Cannot", func, "by 0")
            return

        return func(a, b)
    return inner

a = int(input("What is a:"))
b = int(input("What is b:"))

@smart_divide
def divide(a, b):
   print(a/b) 
   
divide(a,b)

@smart_divide
def multiply(a, b):
    print(a*b)

multiply(a, b)

The result of this is

I am going to <function divide at 0x0325F268> 4 and 2
2.0
I am going to <function multiply at 0x0325F1D8> 4 and 2
8

I read that you had to call the function with () instead of using print but I'm still getting this.

Jv Jones
  • 3
  • 1

1 Answers1

0
def smart_divide(func):
    def inner(a, b):
        print("I am going to", func.__name__, a, "and", b)
        if b == 0:
            print("Cannot", func.__name__, "by 0")
            return

        return func(a, b)
    return inner
Amirul Akmal
  • 401
  • 6
  • 13