0
我对Python非常陌生,所以我认为我正在做一些非常错误的事情,但我没有看到什么,Google也没有帮助过这么多。这有什么问题?将构造函数参数传递给生成默认值的函数失败
def lookup_permille(name):
# TODO: implement a permille lookup table
return 0
def lookup_known_product(name):
# TODO: implement a known product lookup table
return 0
class ProductEntry:
def __init__(self, source, name, price, volume, permille = lookup_permille(name), known_product_id = lookup_known_product(name), category = 0):
self.source = source
self.name = name
self.price = price
self.volume = volume
self.permille = permille
self.price_per_permille = self.permille/self.price;
self.category = category
self.known_product_id = known_product_id
调用的ProductEntry
构造失败:定义函数时
def __init__(self, source, name, price, volume, permille = lookup_permille(name), known_product_id = lookup_known_product(name), category = 0):
NameError: name 'name' is not defined
谢谢,我想我期待从Python的太多:d我的意思是,这将不是在C++的工作,由于某种原因我预想的Python是一个神奇的“做它,所有的”啄:d –