An error 'str' object is not callable is displayed on executing below code containing Inheritenace implementation. | Selenium Python Forum
A
Arvind C Posted on 27/07/2020

class Employee:
def empname(self,empname):
self.empname = empname
# def show(self,empname):
# print(self.empname)
class EmployeeID(Employee):
def showempid(self,empid):
self.empid = empid
def show(self):
print("{}:{}".format(self.empname,self.empid))

r1 = EmployeeID()
r1.empname("Arvind")
r1.showempid("000239521")
r1.show()
r1.empname("Rahul")
r1.show()

class Employee:
    def empname(self,empname):
        self.empname = empname
#     def show(self,empname):
#         print(self.empname)   
class EmployeeID(Employee):
    def showempid(self,empid):
       self.empid = empid
    def show(self):
        print("{}:{}".format(self.empname,self.empid))

r1 = EmployeeID()
r1.empname("Ravi")
r1.showempid("000239521")
r1.show()
r1.empname("Rahul")
r1.show()

J
Jaspreet Replied on 30/07/2020

Hey, 

The error is coming because of the same name variable and function "empname". Kindly please try running the piece of code given below with other corrections in code as well.

class Employee:
    def empName(self,empname):
        self.empname = empname
        
    def show1(self):    #no parameter is required over here since you are trying to print the name passed in empName function
        print(self.empname)   
        
class EmployeeID(Employee):
    def showempid(self,empid):
        self.empid = empid
        
    def show2(self):
        print("{}:{}".format(self.empname,self.empid))

r1 = EmployeeID()
r1.empName("Ravi")
r1.showempid("000239521")
r1.show1()
r1.show2()
r1.empName("Rahul")
r1.showempid("000239521")
r1.show2()


A
Arvind C Replied on 30/07/2020

Thanks for the reponse. I am not getting the Error and Method Overriding is also achieved


J
Jaspreet Replied on 30/07/2020

Hey, 

Thank you for the update.