<class '_io.TextIOWrapper'>解码方法

问题描述 投票:0回答:1

我正在尝试读取文件的内容:

    with open (os.path.join(root,file),"r",encoding='cp932') as content_file:
        continut=content_file.read()
        print(content_file)

但问题是输出是:

 1 4 0 6 0   |   2 3 . 0 7 . 2 2   0 5 : 0 4 : 2 4 . 3 5 9   | 2 |   < < < < =   O T X R T _ E x e c u t e O T X P r o j e c t ( < R e t u r n > = 6 5 0 9 ) 

有人可以帮我解释一下为什么我有更多空间吗? 我要读的原文件内容是:

14060 | 23.07.22 05:04:24.359 |2| <<<<= OTXRT_ExecuteOTXProject(<Return>=6509)

我搜索并发现问题是来自 open (os.path.join(root,file) 我也尝试过编码“utf-8”,但遇到了嵌套问题:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
python class encoding
1个回答
0
投票

请使用: f = 打开(r'C:\ Users \ uic81314 \ Desktop \ Test_Results \ OtxRuntime.log',模式=“r”,编码=“utf-16”).read() 打印(f)

作为例子

© www.soinside.com 2019 - 2024. All rights reserved.