Blitz is a document-oriented database for Python that is backend-agnostic. It comes with a flat-file database for JSON documents and provides MongoDB-like querying capabilities.
An attribute and a method of a class share the same name. Give unique
names to the two objects or else Python will raise a
TypeError: object is not callable error at runtime. Python raises the
error because the name is associated to the attribute, so when you
insert parentheses after the name, Python actually tries to call the
attribute (although you were trying to call the function).
Per Python style conventions, the author modified his Rectangle class
by deleting the area method. Whenever a module needs to access the
area attribute of a Rectangle instance, the module can just access
the area attribute directly. This also suppresses the
Attribute hides this method error.
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
self.area = width * height
# deleted area method from here
r = Rectangle(3, 4)
print r.area # access the attribute directly now
An attribute and a method of a class share the same name. Give unique names to the two objects or else Python will raise a
TypeError: object is not callable
error at runtime. Python raises the error because the name is associated to the attribute, so when you insert parentheses after the name, Python actually tries to call the attribute (although you were trying to call the function).Affected files
Solutions
Modify the names
Per Python style conventions, the author modified his
Rectangle
class by deleting thearea
method. Whenever a module needs to access thearea
attribute of aRectangle
instance, the module can just access thearea
attribute directly. This also suppresses theAttribute hides this method
error.References