如何获取文件最后一次在Python中修改的时间? [英] How do I get the time a file was last modified in Python?

查看:279
本文介绍了如何获取文件最后一次在Python中修改的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设文件存在(使用os.path.exists(filename)首先确保它存在),如何显示上次修改文件的时间?如果有任何区别,请在Linux上进行.

Assuming the file exists (using os.path.exists(filename) to first make sure that it does), how do I display the time a file was last modified? This is on Linux if that makes any difference.

推荐答案

操作系统. stat()

import os
filename = "/etc/fstab"
statbuf = os.stat(filename)
print("Modification time: {}".format(statbuf.st_mtime))

Linux不会记录文件的创建时间(对于大多数文件系统,.)

Linux does not record the creation time of a file (for most fileystems).

这篇关于如何获取文件最后一次在Python中修改的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆