转换°(度)字符gg°mm''ss'数据

convert ° (degree) character gg°mm'' ss' data

我需要将 gg°mm"ss' 格式的坐标数据转换为十进制格式。 我在模块的头部使用 # -*- coding: utf-8 -*- #

原始文件中的数据行:

    06:58   15:07:26    -53°08'00.7"   -70°51'27.5"   2404.1   746.1   -2.4 22.3    0.3675

当文件被处理并消除空格并用查找器写入其他行时:

06:58 15:07:26 -53∞08'00.7" -70∞51'27.5" 2404.1 746.1 -2.4 22.3 0.3765

我需要将 -53°08'00.7" 转换为十进制格式 -gg,ddddd。 但我不明白,因为在 Spyder 中是正确的,但在 finder 中不是。有什么提示吗? 这是代码的一部分:

if os.path.exists(name):  
    with open(name, 'r', encoding="utf-8", errors="surrogateescape") as f:  
        for line in itertools.islice(f, 2, None):  # start=2, stop=None  
            if not '//' in line:  
                linea1 = re.sub('[ \t]+' , ' ', line)  
                signo = linea1.find('-',0,6)  
                if signo == -1 :  
                    file_mov.write(linea1)  

看看以下内容是否有帮助。它并不优雅,但它应该让您对发生的事情有一个很好的了解。

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

import re

degree_sym = u'\N{DEGREE SIGN}'
sample = u'  06:58   15:07:26    -53\N{DEGREE SIGN}08\'00.7"   -70\N{DEGREE SIGN}51\'27.5"   2404.1   746.1   -2.4 22.3    0.3675'

regex = r'(-?)(\d+)'+ degree_sym + r"(\d+)'" + r'(\d+|\d+\.\d+)"'

converted_words = []

for word in sample.split():
        m = re.match(regex, word, flags=re.UNICODE)
        if m:
                sign    = int(m.groups()[0]+'1')
                degrees = float(m.groups()[1])
                minutes = float(m.groups()[2])/60.0
                seconds = float(m.groups()[3])/3600.0
                result  = "{0:.5f}".format(sign*(degrees+minutes+seconds))
                converted_words.append(result)
        else:
                converted_words.append(word)
answer = " ".join(converted_words)
print(answer)

输出:

06:58 15:07:26 -53.13353 -70.85764 2404.1 746.1 -2.4 22.3 0.3675