【发布时间】:2021-02-06 22:07:51
【问题描述】:
我试图在我制作的这个类中重载我的运算符。我做了这个植物课,我正在尝试把它打印出来。我对此仍然很陌生,所以我的理解可能不是最好的,但是您可以提供的任何帮助都会很棒。这是我的 mmain.py:
import Fungi_
import Animal
import inheritance
import Monera
import Plant
grass = Plant.Ferns("Good", "large")
print(grass.scent() + grass.size())
这是我的类和子类,
from inheritance_assignment import living_thing
class Plant(living_thing):
def __init__(self, type):
self.type = type
class Equiseta(Plant):
def __init__(self, type, color):
self.type = type
self.color = color
class Lycopodia(Plant):
def __init__(self, color, size):
self.color = color
self.size = size
class Gymnosperms(Plant):
def __init__(self, size, color):
self.size = size
self.color = color
class Anginosperm(Plant):
def __init__(self, length, color):
self.length = length
self.color = color
class Ferns(Plant):
def __init__(self, scent, size):
self.scent = scent
self.size = size
class Mosses(Plant):
def __init__(self, wetness, size):
self.wetness = wetness
self.size = size
这是它给我的错误
Traceback (most recent call last):
File "main.py", line 8, in <module>
print(grass.scent() + grass.size())
TypeError: 'str' object is not callable
任何信息都将是盛大的!提前致谢。
【问题讨论】:
-
错误信息很清楚。你为什么要打电话给
grass.scent和grass.size?
标签: python inheritance overloading