python - 将python编解码器转换为文本

标签 python file codec

代码:

ff = open(outfile, 'rw').read().replace('\n','')
for n in list(eval(ff)):
    c = []
    c.append(n)
    print c

文件输出:

((592, (1, '\xd0\x94\xd0\xbe\xd0\xb3\xd1\x81\xd1\x8f.', 0), (2, '\xd0\xa3\xd1\x81\xd0\xbe\xd1\x80\xd0\xbe\xd0\xbc.', 0), 
...

但我想看字母,而不是编码。我 使用 .decode() 不同的编解码器,但只改变了编码,没有得到字母

最佳答案

我猜你正试图用 python 读取一个文件并逐行打印它。你可以使用这个片段:

import sys
outfile = 'file path'

with open(outfile, 'r') as f:
    lines = f.readlines()
    for line in lines:
        sys.stdout.write(line)

关于python - 将python编解码器转换为文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29035017/

相关文章:

python - 在列表之间添加逗号和 and

python - 无法在 python graphql 框架中启用 CORS/允许 header - ariadne

file - 使用单独的文件作为摘要

java - 寻找好的Java音频压缩库

android - 具有硬件编解码器支持的 FFMPEG

python - 为什么我的图像按钮没有出现?

python - 在 visualize_cv2.py 中列出超出范围的索引

Android:如何在首次运行时将文件从 Assets 加载到 SD?

c - 将文件内容扫描到链接列表中

video - 选择用于屏幕录制的视频编解码器