我需要帮助。我用PyCharm进行编码,它一直向我显示未解析的参考'模型'。不使用参数'model'值,getter签名应该是(self)。请问我该如何解决这个问题。
class ProductObject:
def __init__(self, product, brand, car, model, year):
self.product = product
self.brand = brand
self.car = car
self.model = model
self.year = year
def set_product(self, product):
self.product = product.capitalize()
def get_product(self):
return self.product
product = property(get_product, set_product)
def set_brand(self, brand):
self.brand = brand.title()
def get_brand(self):
return self.brand
brand = property(get_brand, set_brand)
def set_car(self, car):
self.car = car.title()
def get_car(self):
return self.car
car = property(get_car, set_car)
def set_model(self):
self.model = model.title()
def get_model(self, model):
return self.model
model = property(get_model, set_model)
def set_year(self):
self.year = year.int()
def get_year(self, year):
return self.year
year = property(get_year, set_year)
答案 0 :(得分:0)
您需要更改方法的参数。获取方法只需自我,并设置方法需要自我和模型作为参数。
def set_model(self, model):
self.model = model.title()
def get_model(self):
return self.model
修改强> 继承你的班级:
class YourSubclass(ProductObject):
#code of your subclass which inherit from ProductObject class
模块: 如果你想要创建模块,你应该检查这个Module structure 它只是带有init.py文件的类。然后,您可以使用普通的import语句导入类。这是另一个链接,其中包含有关init.py文件的信息:Init.py structure