Python docx を使用して単語文書に度記号を追加しようとすると、関数は次のように定義されます。
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
私は多くのバリエーションを試しましたが、何もうまくいきませんでした.エンコードについての理解が不足しているため、これが得られない可能性があります.