Movatterモバイル変換
[0]ホーム
[Python-Dev] PEP 410 (Decimal timestamp): the implementation is ready for a review
Victor Stinnervictor.stinner at gmail.com
Thu Feb 16 14:20:35 CET 2012
> If I run your snippet and inspect modification times using `stat`, the> difference is much smaller (around 10 ns, not 1 ms):>> $ stat test | \grep Modify> Modify: 2012-02-16 13:51:25.643597139 +0100> $ stat test2 | \grep Modify> Modify: 2012-02-16 13:51:25.643597126 +0100The loss of precision is not constant: it depends on the timestamp value.Another example using the stat program:------------import decimal, os, shutil, timetry: os.unlink("test")except OSError: passtry: os.unlink("test2")except OSError: passopen("test", "x").close()shutil.copy2("test", "test2")print(os.stat("test", timestamp=decimal.Decimal).st_mtime)print(os.stat("test2", timestamp=decimal.Decimal).st_mtime)print(os.stat("test2", timestamp=decimal.Decimal).st_mtime -os.stat("test", timestamp=decimal.Decimal).st_mtime)os.system("stat test|grep ^Mod")os.system("stat test2|grep ^Mod")------------Outputs:------------$ ./python x.py1329398229.9188586001329398229.918208829-0.000649771Modify: 2012-02-16 14:17:09.918858600 +0100Modify: 2012-02-16 14:17:09.918208829 +0100$ ./python x.py1329398230.8628585881329398230.861343658-0.001514930Modify: 2012-02-16 14:17:10.862858588 +0100Modify: 2012-02-16 14:17:10.861343658 +0100$ ./python x.py1329398232.4508585701329398232.450067044-0.000791526Modify: 2012-02-16 14:17:12.450858570 +0100Modify: 2012-02-16 14:17:12.450067044 +0100$ ./python x.py1329398233.0908585611329398233.090853761-0.000004800Modify: 2012-02-16 14:17:13.090858561 +0100Modify: 2012-02-16 14:17:13.090853761 +0100------------The loss of precision is between 1 ms and 4 us. Decimal timestampsdisplay exactly the same value than the stat program: I don't see anybug in this example.VictorPS: Don't try os.utime(Decimal) with my patch, the conversion fromDecimal to _PyTime_t does still use float internally (I know thisissue, it should be fixed in my patch) and so loss precision ;-)
More information about the Python-Devmailing list
[8]ページ先頭