desihub / specter

A toolkit for simulating multi-object spectrographs
Other
8 stars 7 forks source link

python3 updates #39

Closed sbailey closed 7 years ago

sbailey commented 7 years ago

This PR makes a bunch of little changes for python3 compatibility. The code works for both python 2.7 and 3.5, so I'll try to support both for now, though python 2.7 support could be dropped without warning if some incompatibility arises. I think I've configured Travis to test both as well.

A few notes:

weaverba137 commented 7 years ago

This all looks good to me, but for maximum assurance that 2.7 & 3.5 behave the same, you should also add unicode_literals to the from __future__ statements. This is particularly important if you do any reading or writing of string data (i.e. non-numeric text) from files.

sbailey commented 7 years ago

I added unicode_literals throughout except for bin/specter, since numpy dtypes doesn't work with unicode under python 2.7 (but it does under 3.5). e.g. this works for python 2.7 without unicode_literals and python 3.5 either way:

x = np.zeros(10, dtype=[('BLAT', 'f8')])

but adding "from future import unicode_literals" breaks it on python 2.7 (though it continues to work on python 3.5).

If really needed, I could use str('BLAT') to get away from unicode, but that is basically just working around a bug in numpy that doesn't happen unless unicode_literals is invoked anyway.