Python列表:如何按时间戳排序?(应用程序引擎相关)
我的提要模型中有十个实体(这是一个应用程序引擎模型) 因此,我使用db.key()方法调用我的实体: 但是现在,如何根据时间戳对提要进行排序?(我希望最新的提要在顶部,最旧的提要在底部) 我可以在原始时间戳上使用任何排序函数吗?(我的大致计划是根据原始时间戳进行排序,然后将时差人性化) PS:我不打算使用GQL查询来根据时间戳查询我的实体,因为我以键列表的形式获取输入。使用db.key()是一种更快的方法 希望我提供了足够的信息。希望听到您的想法/解决方案Python列表:如何按时间戳排序?(应用程序引擎相关),python,google-app-engine,Python,Google App Engine,我的提要模型中有十个实体(这是一个应用程序引擎模型) 因此,我使用db.key()方法调用我的实体: 但是现在,如何根据时间戳对提要进行排序?(我希望最新的提要在顶部,最旧的提要在底部) 我可以在原始时间戳上使用任何排序函数吗?(我的大致计划是根据原始时间戳进行排序,然后将时差人性化) PS:我不打算使用GQL查询来根据时间戳查询我的实体,因为我以键列表的形式获取输入。使用db.key()是一种更快的方法 希望我提供了足够的信息。希望听到您的想法/解决方案 import operator
import operator
...
for feed in sorted(feeds, key=operator.attrgetter('timestamp'), reverse=True):
print humanizeTimeDiff(feed.timestamp)
feeds = db.keys(list_of_keys)
# this loop below prints the feed
for feed in feeds:
print humanizeTimeDiff(feed.timestamp)
# humanizeTimeDiff is a function to change the raw timestamp into a human friendly
# version: eg-> 10 mins ago, 20 seconds ago
import operator
...
for feed in sorted(feeds, key=operator.attrgetter('timestamp'), reverse=True):
print humanizeTimeDiff(feed.timestamp)