python3-day5(模块)

Posted willian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3-day5(模块)相关的知识,希望对你有一定的参考价值。

1.获取路径

import os,sys

#获取全部路径
print(os.path.abspath(__file__))
#获取目录
print(os.path.dirname(os.path.abspath(__file__)))
#获取文件名
print(os.path.basename(__file__))

2.时间模块time、datetime

#时间戳-->struct_time
print(time.time())
print(time.gmtime(time.time()))

#struct_time-->时间戳
print(time.localtime())
print(time.mktime(time.localtime()))

#字符串-->struct
print(time.strptime("20150505","%Y%m%d"))
#struct-->字符串
print(time.strftime("%Y%m%d",time.localtime()))

 技术分享

以上是关于python3-day5(模块)的主要内容,如果未能解决你的问题,请参考以下文章