A module is attempting to use an undefined member of a class. Implement the member or remove the statement referencing the undefined member or else Python will raise a runtime error and the module will not execute.
When a module attempts to use a member of a class which is not defined in that class, Python raises an AttributeError and stops executing the program. Either implement the undefined member or remove the statement referencing the undefined member or else the module will not be able to execute successfully.
The module below attempts to call a function from the Rectangle class called area. This raises the class has no member error because the area function in undefined in the Rectangle class.
Warning
The code below is an example of an error. Using this code will create bugs in your programs!
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
r = Rectangle(5, 4)
print r.area() # no such member in Rectangle classThe updated module below implements the area member. Now that the function is defined, the class has no member error is suppressed.
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def area():
return self.width * self.height
r = Rectangle(5, 4)
print r.area() # ok nowThe updated module below suppresses the class has no member error by using known defined class members to work around the problem. Rather than trying to use the undefined member area, the module multiples the width and height attributes of the instance to get the desired value.
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def area():
return self.width * self.height
r = Rectangle(5, 4)
area = r.width * r.height # using known members to get the desired value
print area- Pylint - E1101