My code is skipping inner function | Selenium Python Forum
20% Off Lockdown Learning Discount Avail Now

my code is skipping inner function

A
Ajaypal Gill Post on 26/04/2020

'''
Created on Apr 25, 2020

@author: ajgill
'''

def smartD(func):
    def inner(self):
        global a
        global b
        #self.a = a
        #self.b = b
        if(self.b==0):
            print("Dude, you are doing something wrong")
            quit()
        return func(self)
    return inner
        
class Decor:   
    a= input("Enter First num: ")
    b= input("Enter Second Num: ")
    @smartD
    def add (self):
        global a
        global b
        c= int (self.a)/int (self.b)
        print(c)
d=Decor()
d.add()

S

Instructor

Sejal Reply on 28/04/2020

Hey Ajaypal, 

Please try this :

def smartD(func):
def inner(self,b):
print("Dividing two numbers ",a, " and ",b)
if(b==0):
print("Dude, you are doing something wrong")
quit()

return func(self,b)
return inner

a= input("Enter First num: ")
# b= input("Enter Second num: ")

class Decor:
global a,b
@smartD
def div(self,b):
c= int(a)/b
print("Output is : "+str(c))

d=Decor()
d.div(0)