Я получаю странные результаты и, наконец, заметил, что моя привычка помещать пробелы в кортеж вызывает проблему. Если вы можете воспроизвести эту проблему и сказать мне, почему она работает таким образом, вы бы спасли то, что осталось от моих волос. Спасибо!
jcomeau@intrepid:/tmp$ cat haversine.py
#!/usr/bin/python
def dms_to_float(degrees):
d, m, s, compass = degrees
d, m, s = int(d), float(m), float(s)
float_degrees = d + (m / 60) + (s / 3600)
float_degrees *= [1, -1][compass in ['S', 'W', 'Sw']]
return float_degrees
jcomeau@intrepid:/tmp$ python
Python 2.6.7 (r267:88850, Jun 13 2011, 22:03:32)
[GCC 4.6.1 20110608 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from haversine import *
>>> dms_to_float((111, 41, 0, 'SW'))
111.68333333333334
>>> dms_to_float((111,41,0,'Sw'))
-111.68333333333334
С пробелами в кортеже ответ неверный. Без ответа правильный.