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‘
原文地址:https://www.cnblogs.com/baxianhua/p/10102124.html
时间: 2024-11-29 10:06:00