python getatime() 檢視檔案的訪問時間
阿新 • • 發佈:2018-12-11
import time,os def main(): file_name=r'C:\Temp\Req.xml' file_times_access=time.localtime(os.path.getatime(file_name)) year_access=file_times_access.tm_year month_access=file_times_access.tm_mon day_access=file_times_access.tm_mday hour_access=file_times_access.tm_hour minute_access=file_times_access.tm_min second_access=file_times_access.tm_sec print('file is viewed on:',year_access,'year',month_access,'month',day_access,'day',hour_access,'hour',minute_access,'minute',second_access,'second') if __name__=='__main__': main()
檔案路徑使用r,/,\\都可以
file_name='C:\\Temp\\t.txt'
file_name='C:/Temp/t.txt'