尝试使用python docx将度数符号添加到word文档中,我的函数定义如下:
def convert_decimal_degrees2DMS(self,value):
#value = math.fabs(value)
degrees = int(value)
submin = math.fabs( (value - int(value) ) * 60)
minutes = int(submin)
subseconds = round(math.fabs((submin-int(submin)) * 60),1)
subseconds = int(subseconds)
self.angle = str(degrees) + " Degrees " + str(minutes) + " Minutes " +\
str(subseconds)[0:2] + " Seconds "
#self.angle = str(degrees) + "-" + str(minutes) + "-" + str(subseconds)
#return str(degrees) + "-" + str(minutes) + "-" + str(subseconds)
#degree = u'\N{DEGREE SIGN}'.encode('utf-8')
return "{0}{1}{2}'{3}''".format(degrees,u'°'.encode('cp1252'),minutes,subseconds)
我不断收到的错误是:
File "lxml.etree.pyx", line 921, in lxml.etree._Element.text.__set__ (src\lxml\lxml.etree.c:41467)
File "apihelpers.pxi", line 652, in lxml.etree._setNodeText (src\lxml\lxml.etree.c:18888)
File "apihelpers.pxi", line 1335, in lxml.etree._utf8 (src\lxml\lxml.etree.c:24701)
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters
Exception AttributeError: "'NoneType' object has no attribute 'print_exc'" in <function _remove at 0x01E0F770> ignored
我尝试了很多变体,但没有任何效果,我担心这可能是因为我对编码缺乏了解,我没有得到这个。