當我做到以下幾點:在運行時動態的屬性添加一個類在Python
def Welcome(email, temporaryPassword):
model = object()
model.TemporaryPassword = temporaryPassword
model.Email = email
我得到一個錯誤:
AttributeError: 'object' object has no attribute 'TemporaryPassword'
如何動態地創建一個對象,就像我現在這樣?
的可能重複[蟒蛇:如何動態地添加屬性類(http://stackoverflow.com/questions/1325673/python-how-to-add-property-to-a -class-動態地) – 2011-09-12 05:09:20