python OS使用积累

  • time

time.time()

返回当前时间,这样的获得的是时间戳。精确到纳秒

  • datetime
datetime.datetime.today()

datetime.datetime.now()

获取时间,但是格式和time不一样。

运行结果为:

2019-01-23 13:15:50.919301

  • .strftime()

可以格式化时间。例如:

datetime.datetime.now().strftime('%Y%m%d')
  • os.path.exists(root)

可以判断root所表示的地址目录是否存在。

  • os.listdir()

用于返回指定的文件夹包含的文件或文件夹的名字的列表。

  • os.path.join()

将多个路径组合后返回。

例如:

fullfilename=os.path.join(root,file)

    root 和 file结合生成新的路径。

  • .startwith()

方法用于检查字符串是否是以指定子字符串开头。

例如:

file.startwith('cash')

检查file是不是以'cash'开头的字符串。

猜你喜欢

转载自blog.csdn.net/xt_ecnu/article/details/86606898
今日推荐