In the Quick Python Book, both print and online versions, section 15.5.1 lists the following code sample which is contained in file circle.py:
"""circle module: contains the Circle class."""
class Circle:
"""Circle class"""
# Variable containing a list of all circles which have been created.
all_circles = []
pi = 3.14159
def __init__(self, r=1):
"""Create a Circle with the given radius"""
self.radius = r
self.__class__.all_circles.append(self)
def area(self):
"""determine the area of the Circle"""
return self.__class__.pi * self.radius * self.radius
@staticmethod
def total_area():
total = 0
for c in Circle.all_circles:
total = total + c.area()
return total
The book then directs the reader to "...interactively type the following":
>>> import circle
>>> c1 = circle.Circle(1)
>>> c2 = circle.Circle(2)
>>> circle.Circle.total_area()
The fourth command, circle.Circle.total_area(), produces the following error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: type object 'Circle' has no attribute 'total_area'
Any ideas how to fix this?
