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

yipeiwu_com6年前Python基础

本文实例讲述了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)

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

相关文章

Pytorch to(device)用法

如下所示: device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") model.to(devi...

Python中每次处理一个字符的5种方法

目的 对字符串的每个字符进行处理,其实每个字符(Char)就是一个长度为1的字符串。 方法 1.使用内建函数list() 复制代码 代码如下: >>> A_string...

Django如何简单快速实现PUT、DELETE方法

使用django的小伙伴们应该都知道我们是无法开心的处理PUT跟DELETE的 $.ajax({ url: 'XXX', type: 'PUT', dataType: '...

Python多线程和队列操作实例

Python3,开一个线程,间隔1秒把一个递增的数字写入队列,再开一个线程,从队列中取出数字并打印到终端 复制代码 代码如下: #! /usr/bin/env python3 impor...

Python 实现域名解析为ip的方法

今天得了一批域名,需要把域名解析成ip 因为量比较大所以采用了多进程和队列的方式 from multiprocessing import Process,Queue,Pool imp...