class WineComponents(object):
def __init__(self, aroma, body, acidity, flavor, color):
self.aroma = aroma
self.body = body
self.acidity = acidity
self.flavor = flavor
self.color = color
可以这样实例化:
wine = Color(aroma='80%', body='30%', acidity='35%', flavor='90%', color='Red')
然后我希望能够创建将继承WineComponents()
的特定类:
class Color(WineComponents):
def receipe(self):
pass
在某些条件下,也要有自己的属性,比如:
class Color(WineComponents):
if self.color == 'Red':
region = 'France'
type = 'Bordeaux'
def receipe(self):
pass
调用属性时使用:
print wine.region
但这不起作用:
if self.color == 'Red':
NameError: name 'self' is not defined
有解决办法吗?你知道吗
你可以用房产来做
可以这样称呼:
这是我的五便士:
相关问题 更多 >
编程相关推荐