Home > Backend Development > Python Tutorial > python获得文件创建时间和修改时间的方法

python获得文件创建时间和修改时间的方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 11:19:13
Original
1538 people have browsed it

本文实例讲述了python获得文件创建时间和修改时间的方法。分享给大家供大家参考。具体如下:

这里需要用户从控制台输入文件路径

import os.path, time
import exceptions
class TypeError (Exception):
  pass
if __name__ == '__main__':
 if (len(os.sys.argv) < 1):
   raise TypeError()
 else:
   print "os.sys.argv[0]: %s" % os.sys.argv[0]
   # os.sys.argv[0] is the current file, in this case, file_ctime.py
 f = os.sys.argv[0]
 mtime = time.ctime(os.path.getmtime(f))
 ctime = time.ctime(os.path.getctime(f))
 print "Last modified : %s, last created time: %s" % (mtime, ctime)

Copy after login

希望本文所述对大家的Python程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template