python获得文件创建时间和修改时间的方法
2015-06-30 00:00
971 查看
本文实例讲述了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程序设计有所帮助。
相关文章推荐
- python过滤字符串中不属于指定集合中字符的类实例
- python判断一个集合是否包含了另外一个集合中所有项的方法
- python检查序列seq是否含有aset中项的方法
- python简单判断序列是否为空的方法
- python实现爬取千万淘宝商品的方法
- Python实现监控程序执行时间并将其写入日志的方法
- python的keyword模块用法实例分析
- Python项目一:即时标记
- Python中super关键字的作用
- 深刻理解Python中的元类(metaclass)
- Python的getattr(),setattr(),delattr(),hasattr()
- Python 闭包
- 关于Python的super用法
- [Python] Python 之 __new__() 方法与实例化
- [深入Python]__new__和__init__
- Python学习笔记 - 迭代器Iterator
- Python学习笔记 - 迭代器Iterator
- Python学习笔记 - 生成器generator
- Python学习笔记 - 生成器generator
- 列表元素的个数及元素的值可改变;元组值不可以改变-《Python核心编程》P26