db.Model类变量和__init__ [英] db.Model class variables and __init__

查看:111
本文介绍了db.Model类变量和__init__的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(Python和GAE的新手)

我正在寻找一个关于在db.Model子类中使用类变量的解释,它被视为实例变量。为什么在类范围内声明这些内容,而不是在 __ init __ 中声明?这是一种特殊的GAE要求吗?

解决方案

是的,这是GAE特有的编程模型。您可以将类属性视为表定义。实例属性是行的内容,它们由metclass db.PropertiedClass动态填充。



如果你有一个问题,有兴趣的人一定会看看源代码:
http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/ext/db/ init .py


(New to Python and GAE)

I'm looking for an explanation to the use of class variables in db.Model subclasses, which are treated like instance variables. Why are these declared in class scope and not in __init__? Is this some kind of special GAE requirement?

解决方案

Yes, this is a programming model special to GAE. You can think of the class properties as the table definition. The instance properties are the contents of a row, they are populated on the fly by the metclass db.PropertiedClass.

There is a lot going on under the hood, if you are interested always have a look at the source: http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/ext/db/init.py

这篇关于db.Model类变量和__init__的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆