Python os.utime() 方法
python os.utime() 方法
os.utime() 方法用于設(shè)置指定路徑文件最后的修改和訪問時(shí)間。
在unix,windows中有效。
語法
utime()方法語法格式如下:
os.utime(path, times)
參數(shù)
- path -- 文件路徑
- times -- 如果時(shí)間是 none, 則文件的訪問和修改設(shè)為當(dāng)前時(shí)間 。 否則, 時(shí)間是一個(gè) 2-tuple數(shù)字, (atime, mtime) 用來分別作為訪問和修改的時(shí)間。
返回值
該方法沒有返回值。
實(shí)例
以下實(shí)例演示了 utime() 方法的使用:
#!/usr/bin/python # -*- coding: utf-8 -*- import os, sys # 顯示文件的 stat 信息 stinfo = os.stat('a2.py') print stinfo # 使用 os.stat 來接收文件的訪問和修改時(shí)間 print "a2.py 的訪問時(shí)間: %s" %stinfo.st_atime print "a2.py 的修改時(shí)間: %s" %stinfo.st_mtime # 修改訪問和修改時(shí)間 os.utime("a2.py",(1330712280, 1330712292)) print "done!!"
執(zhí)行以上程序輸出結(jié)果為:
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 的訪問時(shí)間: 1330498070 a2.py 的修改時(shí)間: 1330498074 done!!
相關(guān)文章
- Python 教程
- Python 中文編碼
- Python pass 語句
- Python 列表 List
- Python GUI編程 Tkinter
- Python2 與 Python3?? 版本區(qū)別
- Python 數(shù)組
- Python 二維數(shù)組
- Python 集合
- Python 節(jié)點(diǎn)
- Python 高級(jí)鏈表
- Python 二叉樹
- Python 樹遍歷算法
- Python 大O符號(hào)
- Python 攤銷分析
- Python 算法理由
- Python3 解釋器
- Python3 字典(Dictionary)
- Python3 if else 語句
- Python3 內(nèi)置函數(shù)