[英]How do I get the time a file was last modified in Python?
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? 假设文件存在(使用
os.path.exists(filename)
首先确保它存在),如何显示文件上次修改的时间? This is on Linux if that makes any difference. 这是在Linux上,如果这有任何区别。
>>> import os
>>> f = os.path.getmtime('test1.jpg')
>>> f
1223995325.0
since the beginning of (epoch) 自(epoch)开始
import os
filename = "/etc/fstab"
statbuf = os.stat(filename)
print("Modification time: {}".format(statbuf.st_mtime))
Linux does not record the creation time of a file ( for most fileystems ). Linux不记录文件的创建时间( 对于大多数文件系统 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.