使用变量获取属性值

时间:2013-06-10 01:39:01

标签: python google-app-engine google-cloud-datastore gql gqlquery

我希望能够使用变量从我的数据库中获取值,最后一行是我想要实现的。

class Data(db.Model):
  property = db.StringProperty()

data = Data(property = 'value')
data.put()

query = db.GqlQuery("SELECT * FROM Data")

myvar = 'property'

for line in query:
  line[myvar]

1 个答案:

答案 0 :(得分:1)

谢谢voscausa,

class Data(db.Model):
  property = db.StringProperty()

data = Data(property = 'value')
data.put()

query = db.GqlQuery("SELECT * FROM Data")

myvar = 'property'

for line in query:
  getattr(line, myvar)