我见过多次的例子是这样的:定义属性在Python对象/实体/谷歌应用程序引擎
from google.appengine.ext import db
import datetime
class Book(db.Expando):
pass
obj = Book()
obj.title = 'The Grapes of Wrath'
obj.author = 'John Steinbeck'
obj.copyright_year = 1939
obj.author_birthdate = datetime.date(1902, 2, 27)
obj.put()
这是我第一次遇到这种代码,在属性设置外部的类定义。这让我觉得很糟糕。我更喜欢:
class Book(db.Model):
title = db.StringProperty()
author = db.StringProperty()
copyright_year = db.IntegerProperty()
author_birthdate = db.DateProperty()
...
obj = Book(title='The Grapes of Wrath', author='John Steinbeck', copyright_year=1939, author_birthdate=datetime.date(1902, 2, 27))
有人可以提供对作者的实践的性质的保证?何时何地可以接受这种方法?
有人提到,谷歌的数据存储模型允许不寻常的灵活性。我认为这个例子可能是对这个概念的一个可怜和过于微妙的介绍。作者实际上已经指出了这种风格的缺点,然后继续重复它。所以,它可能会有一些优势。
只是好奇 - 哪本书? – 2011-03-04 19:22:39
编程Google App Engine,Dan Sanderson,O'Reilly/Google Press。这是非常分散的,任何人都知道更好的书籍学习谷歌应用程序引擎? – shafty 2011-03-04 19:27:34