Python方法utime()设置path指定的文件的访问和修改时间。
下面是utime()方法-的语法
os.utime(path, times)
path - 这是文件的路径。
times - 这是文件访问和修改时间。如果times为None,则将文件访问和修改时间设置为当前时间。参数times由(atime,mtime)形式的行组成,即(accesstime,modifiedtime)。
以下示例显示了utime()方法的用法。
# !/usr/bin/python import os, sys # 显示文件的统计信息 stinfo=os.stat('a2.py') print stinfo # 使用 os.stat 接收文件的 atime 和 mtime print "access time of a2.py: %s" %stinfo.st_atime print "modified time of a2.py: %s" %stinfo.st_mtime # 修改 atime 和 mtime os.utime("a2.py",(1330712280, 1330712292)) print "done!!"
当无涯教程运行上面的程序时,它产生以下输出-
链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-utime.html
来源:LearnFk无涯教程网
posix.stat_result(st_mode=33188, st_ino=3940649674337682L, st_dev=277923425L, st _nlink=1, st_uid=400, st_gid=401, st_size=335L, st_atime=1330498070, st_mtime=13 30498074, st_ctime=1330498065) access time of a2.py: 1330498070 modified time of a2.py: 1330498074 done!!
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Python实战 · 从0到1搭建直播视频平台 -〔Barry〕