• UnicodeDecodeError: 'ascii' codec can't decode byte 0xa3 in position 1: ordinal not in range(128)


    使用codecs模块

    codecs模块能在处理字节流的时候提供很大帮助。你可以用定义的编码来打开文件并且你从文件里读取的内容会被自动转化为Unicode对象。

    试试这个:

    >>> importcodecs
    >>> fh =codecs.open("/tmp/utf-8.txt","w","utf-8")
    >>> fh.write(u"u2013")
    >>> fh.close()
    import codecs
    with codecs.open(file_path,"utf-8") as fp:
        for line in fp:
    
            log_obj = XAdNginxLog(p_line=line)
  • 相关阅读:
    iOS开源控件库收集
    Ruby中的几种除法
    Font
    PlaySound
    STL
    APIs
    cin and cout
    CreateWindow
    Introducing Direct2D
    VC 常用代码
  • 原文地址:https://www.cnblogs.com/zhaoyingjie/p/8893232.html
Copyright © 2020-2023  润新知