Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.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_Python 2.7_Datetime - Fatal编程技术网

在python中反转日期时间列表

在python中反转日期时间列表,python,python-2.7,datetime,Python,Python 2.7,Datetime,我使用以下代码生成了时间戳列表: no_of_readings = int(math.ceil(no_of_seconds/measurement_interval)) timestamps = [time_intervals[0]["timestamp"] - timedelta(seconds=x * measurement_interval) for x in range(1, int(math.ceil(no_of_readi

我使用以下代码生成了时间戳列表:

    no_of_readings = int(math.ceil(no_of_seconds/measurement_interval))
    timestamps = [time_intervals[0]["timestamp"] - timedelta(seconds=x * measurement_interval)
                       for x in range(1, int(math.ceil(no_of_readings)))
                 ]
    timestamps.reverse()

但是当我尝试反转时间戳列表时,它返回none。 我应该如何解决这个问题


我认为问题在于元素的形式是
dataetime.datetime(2018,02,16,0,0,1)
。如果您有任何帮助,我们将不胜感激。

列表。reverse方法会将列表反转到位,但实际上不会返回列表。因此,在执行您显示的代码之后,
timestamps
将包含反向列表,即使在您的示例中,
timestamps.reverse()
返回了
None

timestamps.reverse()
print timestamps
print timestamps.reverse()
第二次打印显示reverse()返回的内容

reverse()应该返回None,因此我猜您看到了正确的行为

    >>> z=[x for x in range (1,37)]
    >>> z
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36]
    >>> z.reverse()
    >>> z
    [36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
    >>> res=z.reverse()
    >>> res is None
True

“当我尝试反转时间戳列表时,它返回none”-代码在哪里?如果某个内容已填充,而您将其反转,并且它是
none
-它可能是一个迭代器,通过显示内容一次,然后将其反转将不会得到任何结果-除此之外。。。给我们看看你的