Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.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/1/typo3/2.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查找差异超过24小时的记录_Python - Fatal编程技术网

使用python查找差异超过24小时的记录

使用python查找差异超过24小时的记录,python,Python,我每天运行cron作业,并将最终状态存储在文本文件中 文件数据包含开始时间、结束时间、cron作业名称、日期、状态: 我想检索与系统日期相比处于失败状态超过24小时的作业 与结束时间和datetime函数返回的值进行比较您可以使用os.stat检查何时发生了什么。下面是一个示例代码 def checking_the_dir_info(): x = os.scandir('/path/to/folder/') print('Type of the object resulted by scand

我每天运行cron作业,并将最终状态存储在文本文件中

文件数据包含开始时间、结束时间、cron作业名称、日期、状态:

我想检索与系统日期相比处于失败状态超过24小时的作业


与结束时间和datetime函数返回的值进行比较

您可以使用os.stat检查何时发生了什么。下面是一个示例代码

def checking_the_dir_info():

x = os.scandir('/path/to/folder/')
print('Type of the object resulted by scandir is ', type(x))

for element in x:
    print('The element is on it own ', element, 'and the type of it ', type(element))

y = os.stat('./naber/asd.txt')
print('Last change date ', y.st_mtime)

from time import sleep

sleep(0.1)
z = open('./naber/asd.txt', 'a')
z.write(' Ne olacak bunun sonu :)')
sleep(0.1)

y = os.stat('./naber/asd.txt')
print('Birthtime of the file ', y.st_birthtime)
使用sleep功能,您可以观察到文件夹“naber”中的“某物”已被更改,对于所有其他不同的用例,您可以查看


希望这有帮助

您需要向我们展示您尝试过的代码。使用最多使用regex哪个时间应该与操作系统时间比较?开始时间?或结束时间?将结束时间与日期时间进行比较
def checking_the_dir_info():

x = os.scandir('/path/to/folder/')
print('Type of the object resulted by scandir is ', type(x))

for element in x:
    print('The element is on it own ', element, 'and the type of it ', type(element))

y = os.stat('./naber/asd.txt')
print('Last change date ', y.st_mtime)

from time import sleep

sleep(0.1)
z = open('./naber/asd.txt', 'a')
z.write(' Ne olacak bunun sonu :)')
sleep(0.1)

y = os.stat('./naber/asd.txt')
print('Birthtime of the file ', y.st_birthtime)