2012-01-28 5 views
0

PythonバージョンのGoogle App Engineでクラスの種類からクラスを取得したいと考えています。どのようにクラスの種類を含む文字列でクラスを取得できますか?することができます、あなたはクラスがからロードされたモジュールを知っている限りGoogle App Engineでは、エンティティの種類が指定されていますが、どのようにクラスを取得できますか?

for m in model_list: 
    klass = globals()[m] 
    props = klass.properties() 

答えて

2

あなたはgoogle.appengine.ext.dbパッケージで、class_for_kind("Kind")機能を使用することができます。これを行うには、モデルクラスをインポートする必要があります。

0

さて、あなたはglobals() functionを使用することができ、あなたのモジュールにモデルクラスをインポートした提供しましたモジュールからクラスを取得します。

import models 

model_list = ['Player', 'Country'] 
for m in model_list: 
    klass = getattr(models, m) 
    props = klass.properties() 
0

player_props = Player.properties() 
country_props = Country.properties() 

model_list = ['Player', 'Country'] 

for m in model_list: 
    #foo = theClass 
    props = foo.properties() 
関連する問題