OS File 中的 os.utime(path, times)函

首页 / Python2入门教程 / OS File 中的 os.utime(path, times)函

Python方法utime()设置path指定的文件的访问和修改时间。

os.utime(path, times) - 语法

下面是utime()方法-的语法

os.utime(path, times)
  • path     -  这是文件的路径。

  • times    -  这是文件访问和修改时间。如果times为None,则将文件访问和修改时间设置为当前时间。参数times由(atime,mtime)形式的行组成,即(accesstime,modifiedtime)。

os.utime(path, times) - 示例

以下示例显示了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!!

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

硅谷产品实战36讲 -〔曲晓音〕

Java性能调优实战 -〔刘超〕

Kafka核心技术与实战 -〔胡夕〕

实用密码学 -〔范学雷〕

零基础实战机器学习 -〔黄佳〕

攻克视频技术 -〔李江〕

技术领导力实战笔记 2022 -〔TGO 鲲鹏会〕

Python实战 · 从0到1搭建直播视频平台 -〔Barry〕

B端体验设计入门课 -〔林远宏(汤圆)〕

好记忆不如烂笔头。留下您的足迹吧 :)