Adding a user supplied property (at runtime) to an instance of Expando class in Google App Engine?

前端 未结 2 2018
孤城傲影
孤城傲影 2021-01-28 10:37

By creating datastore models that inherit from the Expando class I can make my model-entities/instances have dynamic properties. That is great! But what I want is the names of t

相关标签:
2条回答
  • 2021-01-28 11:02

    Just found the solution to my own question. It was really simple but as I am a python noob I ended up posting the question that you see above.

    For the code sample that I had used, this is what needs to be done:

    entity_two.__setattr(some_variable, some_value) #where some_variable is populated by user at runtime :)
    
    0 讨论(0)
  • 2021-01-28 11:11

    Usually, we use the setattr function directly.

    setattr( entity_two, 'some_variable', some_value )
    
    0 讨论(0)
提交回复
热议问题