首页 > 代码库 > Python中文字符问题

Python中文字符问题

Python中对中文字符的操作时常会使程序出现乱码

不全然管用的处理方法:

  • 读取数据时使用encode编码为Bytes以保护数据
  • 使用时转化为string并使用decode解码

如:

        title = title_origin[0].encode(‘utf-8‘)
        title = str(title.decode(‘utf-8‘))
<script type="text/javascript"> $(function () { $(‘pre.prettyprint code‘).each(function () { var lines = $(this).text().split(‘\n‘).length; var $numbering = $(‘
    ‘).addClass(‘pre-numbering‘).hide(); $(this).addClass(‘has-numbering‘).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(‘
  • ‘).text(i)); }; $numbering.fadeIn(1700); }); }); </script>

Python中文字符问题