Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python列表:如何按时间戳排序?(应用程序引擎相关)_Python_Google App Engine - Fatal编程技术网

Python列表:如何按时间戳排序?(应用程序引擎相关)

Python列表:如何按时间戳排序?(应用程序引擎相关),python,google-app-engine,Python,Google App Engine,我的提要模型中有十个实体(这是一个应用程序引擎模型) 因此,我使用db.key()方法调用我的实体: 但是现在,如何根据时间戳对提要进行排序?(我希望最新的提要在顶部,最旧的提要在底部) 我可以在原始时间戳上使用任何排序函数吗?(我的大致计划是根据原始时间戳进行排序,然后将时差人性化) PS:我不打算使用GQL查询来根据时间戳查询我的实体,因为我以键列表的形式获取输入。使用db.key()是一种更快的方法 希望我提供了足够的信息。希望听到您的想法/解决方案 import operator

我的提要模型中有十个实体(这是一个应用程序引擎模型)

因此,我使用db.key()方法调用我的实体:

但是现在,如何根据时间戳对提要进行排序?(我希望最新的提要在顶部,最旧的提要在底部)

我可以在原始时间戳上使用任何排序函数吗?(我的大致计划是根据原始时间戳进行排序,然后将时差人性化)

PS:我不打算使用GQL查询来根据时间戳查询我的实体,因为我以键列表的形式获取输入。使用db.key()是一种更快的方法

希望我提供了足够的信息。希望听到您的想法/解决方案

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)