【发布时间】:2019-05-17 13:40:26
【问题描述】:
为什么文件创建时间小于创建前测量的时间?
import os, time
before_creation = time.time()
with open('my_file', 'w') as f:
f.write('something')
creation_time = os.stat('my_file').st_ctime
print(before_creation) # 1545031532.8819697
print(creation_time) # 1545031532.8798425
print(before_creation < creation_time) # False
编辑操作系统是 Linux
【问题讨论】:
-
确认pyfiddle.io .. 有趣。也许这是一个解决问题,因为 time.time() 每秒只更新 50-100 次,而 st_ctime 可能“更快” - 仍然很好奇。 docs.python.org/3/library/time.html#time.time 和 docs.python.org/3.0/library/stat.html#stat.ST_CTIME
-
@PatrickArtner 可能是。我循环运行它,1000 次中约有 4 次记录了预期结果
-
添加到错误跟踪器:bugs.python.org/issue35522
标签: python linux python-3.x file time