【发布时间】:2011-12-18 10:05:32
【问题描述】:
我想在类定义外部定义一个Python属性:
c = C()
c.user = property(lambda self: User.objects.get(self.user_id))
print c.user.email
但我收到以下错误:
AttributeError: 'property' object has no attribute 'email'
在类定义之外定义属性的正确语法是什么?
顺便说一句:我正在使用lettuce
from lettuce import *
from django.test.client import Client
Client.user_id = property(lambda self: self.browser.session.get('_auth_user_id'))
Client.user = property(lambda self: User.objects.get(self.user_id))
@before.each_scenario
def set_browser(scenario):
world.browser = Client()
【问题讨论】:
标签: python properties