【发布时间】:2026-01-10 17:50:01
【问题描述】:
我正在将应用程序从 Datastore 转换为 ndb,但在 xml 导入例程中遇到了问题。问题是我无法以编程方式确定 ndb.model 类的属性是否为多值属性。
我怀疑这是由于缺乏基本的 Python 技能,因为到目前为止我提出的代码表明该值是“可见的”。因此我无法抓住它。请帮忙。
from google.appengine.ext import ndb
class House(ndb.Model):
name = ndb.StringProperty()
rooms = ndb.StringProperty(repeated=True)
print 'Properties:'
for p in House._properties:
print getattr(House,p)
print '\nRepeated:'
for p in House._properties:
print getattr(getattr(House,p),'repeated',None)
这会导致以下结果:
Properties:
StringProperty('rooms', repeated=True)
StringProperty('name')
Repeated:
None
None
【问题讨论】:
-
好的,我查看了源代码,在 Property 类中有一个名为 ´_´repeated 的属性可以访问。它有效,但我有预感“'_'”意味着它不适合外部访问。
标签: python google-app-engine app-engine-ndb