class TestSpeedRetrieval(webapp.RequestHandler):
"""
Test retrieval times of various important records in the BigTable database
"""
def get(self):
commandValidated = True
beginTime = time()
itemList = Subscriber.all().fetch(1000)
for item in itemList:
pass
endTime = time()
self.response.out.write("<br/>Subscribers count=" + str(len(itemList)) +
" Duration=" + duration(beginTime,endTime))
如何将上述内容转换为传递类名的函数? 在上面的示例中,Subscriber(在 Subscriber.all().fetch 语句中)是一个类名,这是您使用 Python 在 Google BigTable 中定义数据表的方式。
我想做这样的事情:
TestRetrievalOfClass(Subscriber)
or TestRetrievalOfClass("Subscriber")
谢谢, 尼尔·沃尔特斯
最佳答案
class TestSpeedRetrieval(webapp.RequestHandler):
"""
Test retrieval times of various important records in the BigTable database
"""
def __init__(self, cls):
self.cls = cls
def get(self):
commandValidated = True
beginTime = time()
itemList = self.cls.all().fetch(1000)
for item in itemList:
pass
endTime = time()
self.response.out.write("<br/>%s count=%d Duration=%s" % (self.cls.__name__, len(itemList), duration(beginTime,endTime))
TestRetrievalOfClass(Subscriber)
关于Python:将类名作为参数传递给函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1436444/