0

I am trying to run the script below, and almost every time I run it it prints out the same number twice. I find it hard to believe that not even one nanosecond passes between the creation of the first file and the second file, since the system calls alone should take at least that long! What am I missing? I'm running on Ubuntu using python version 3.5.1+.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os

with open("test", 'w') as f:
    f.write("hello")

with open("test2", 'w') as f:
    f.write("world")

print(os.stat("test").st_mtime_ns)
print(os.stat("test2").st_mtime_ns)

Typical output:

/tmp $ ./mystery.py 
1478873526316145825
1478873526316145825
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
  • 1
    Does your system actually record the times with nanosecond accuracy? Did you read [the note in the docs](https://docs.python.org/3/library/os.html#os.stat_result.st_ctime_ns)? – BrenBarn Nov 12 '16 at 02:22

1 Answers1

0

You should attempt that for any reasons, that timing is given by your system in its stat call - it is not what Python thinks - it is the only values the system can offer to it.

jsbueno
  • 99,910
  • 10
  • 151
  • 209