这个类应该接受Keys
属性的参数,但是当我尝试时MyUserInstance.Keys('foo')
,它不起作用。相反,它说TypeError: Keys() takes exactly 2 arguments (1 given)
。怎么错了?
# User
class User:
def __init__(self,
Username = 'New User',
**kwargs):
self.Username = Username
self.__dict__.update(kwargs)
@property
def Keys(self,collection):
try:
return {k:1 for k in db.UserPreferences.find_one({
'Type':'VisibleKeys',
'UserID':self._id,
'CollectionName':collection})['Keys']}
except:
return None
def __repr__(self):
return '<User: "%s">' % self.Username