py-tai64 icon indicating copy to clipboard operation
py-tai64 copied to clipboard

SyntaxError: invalid token: 01

Open kseistrup opened this issue 7 years ago • 2 comments

Is this module meant for Python 2 or Python 3? With Python 3 I get this exception:

$ python
Python 3.6.0 (default, Jan 16 2017, 12:12:55)
>>> import tai64n
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/tai64n/__init__.py", line 32
    conversion_table = [(datetime(1972, 01,  1), 10.0),
                                         ^
SyntaxError: invalid token

kseistrup avatar Mar 31 '17 19:03 kseistrup

The peculiar zero-padding of the months in conversion_table only works because we're talking months before August. Because of the initial 0 the number is taken as an octal by Python 2. The Python 2 octal 01 is 0o1 or 0o01 in Python 3.

Had the IERS decided to put leap seconds in August or September, the current code would also have failed in Python 2:

>>> from datetime import datetime
>>> datetime(1972,  08,  1)
  File "<stdin>", line 1
    datetime(1972,  08,  1)
                     ^
SyntaxError: invalid token

kseistrup avatar Mar 31 '17 20:03 kseistrup

The "new" octal syntax is supported by Python 2.7 as well. So if that value is meant to be octal, please use the 0o syntax.

Either way, this issue makes this library completely useless for Python 3, and it's the only one I know of for the task.

AndydeCleyre avatar May 20 '19 18:05 AndydeCleyre