stat方法:

用于获取文件信息,例如创建时间、文件大小等。

1 import os
2 filestate=os.stat("e:/temp/test.txt")
3 print(filestate.st_mtime)# 文件最后修改的时间距离1970/1/1的秒数。
4 
5 import time
6 print(time.localtime(filestate.st_mtime))# 一个元组,含年月日时分秒毫秒。
7 
8 print(filestate.st_size)# 文件大小,按字节计数。

 

path.realpath方法:

1 import os
2 print(os.getcwd())
3 print(os.path.realpath('test.txt'))

效果相当于将realpath方法的参数与当前工作目录组合起来。

相关文章:

  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
  • 2021-06-21
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
猜你喜欢
  • 2022-03-08
  • 2022-12-23
  • 2022-01-08
  • 2021-08-30
  • 2022-12-23
  • 2022-01-18
  • 2021-08-03
相关资源
相似解决方案