我想将字符串中给定位置的字母大写。我对特殊字母有疑问 - 具体来说是波兰字母:例如“±”。理想情况下,该解决方案也适用于法语、西班牙语等(ç、è 等)
dobry="costąm"
print(dobry[4].decode('utf-8').upper())
我得到:
File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc4 in position 0: unexpected end of data
而为此:
print("ą".decode('utf-8').upper())
我根据需要获得Ą。
对位置 0-3 上的字母更感兴趣的是,它在以下情况下可以正常工作:
print(dobry[5].decode('utf-8').upper())
我遇到同样的问题