Python 2.7:字符串乱码问题的解决
2017-11-16 00:00
183 查看
摘要: 当我们从数据库中提取到字符串,需要在控制台输出字符串,却没有显示出我们所期待的效果,多半是编码有问题。unicode(str).decode('unicode_escape').encode('utf-8')
背景:
Python 2.7
Windows 7
Pycharm 2017.1
当我们从数据库中提取到字符串,需要在控制台输出字符串,却没有显示出我们所期待的效果,多半是编码有问题。可以通过下面这一行代码来实现正常的输出:
另外,在代码中出现中文字符串时,应当注意在前面加上u。
背景:
Python 2.7
Windows 7
Pycharm 2017.1
当我们从数据库中提取到字符串,需要在控制台输出字符串,却没有显示出我们所期待的效果,多半是编码有问题。可以通过下面这一行代码来实现正常的输出:
unicode(str).decode('unicode_escape').encode('utf-8')
另外,在代码中出现中文字符串时,应当注意在前面加上u。
相关文章推荐
- Python 2.7:字符串乱码问题的解决
- Python 2.7:字符串乱码问题的解决
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- (转)Python字符串的encode与decode研究心得——解决乱码问题
- Python字符串的encode与decode研究心得——解决乱码问题
- 利用Python从文件中读取字符串(解决乱码问题)
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得乱码问题解决方法
- Python字符串的encode与decode研究心得——解决乱码问题
- Python字符串的encode与decode研究心得乱码问题解决方法