小白教程
所有教程
关于
Search
172.70.130.72
172.70.130.72
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os utime”的源代码
本页内容
上一节:
Python3_os_unlink
下一节:
Python3_os_walk
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.utime(path, times)}}[[Category:python3 os file methods|58]] = Python3 os.utime() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.utime() 方法用于设置指定路径文件最后的修改和访问时间。 在Unix,Windows中有效。 === 语法 === '''utime()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.utime(path, times) </sample> === 参数 === * '''path''' -- 文件路径 * '''times''' -- 如果时间是 None, 则文件的访问和修改设为当前时间 。 否则, 时间是一个 2-tuple数字, (atime, mtime) 用来分别作为访问和修改的时间。 === 返回值 === 该方法没有返回值。 == 以下实例演示了 utime() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 显示文件的 stat 信息 stinfo = os.stat('a2.py') print (stinfo) # 使用 os.stat 来接收文件的访问和修改时间 print ("a2.py 的访问时间: %s" %stinfo.st_atime) print ("a2.py 的修改时间: %s" %stinfo.st_mtime) # 修改访问和修改时间 os.utime("a2.py",(1330712280, 1330712292)) print ("done!!") </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 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) a2.py 的访问时间: 1330498070 a2.py 的修改时间: 1330498074 done!! </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os utime
”。
上一节:
Python3_os_unlink
下一节:
Python3_os_walk