Python 请求帮助:想要读取中文 txt 文件,之前已按可以读取英文或数字 txt 文件最简单的方式进行后报错,现在换了一种新方式如图,却输出一堆解码。我的最终目的是输出中文,而不是解码。

F735_T1971_YYH · 2021年12月29日 · 286 次阅读

测试读取 txt 文件(英文):

with open(r'C:\Users\MacBooK\Desktop\222.txt') as file_object:
    connect = file_object.read()
    print(connect)
    print('系统报告:可正常读取')

测试读取 txt 文件(中文):

path = r'C:\Users\MacBooK\Desktop\111.txt'
with open(path, 'rb') as file_object:
    connects = file_object.read().split()
    print(connects)
    for connect in connects:
        print('{}-{} time'.format(connect, connects.count(connect)))
    print('系统报告:可正常读取')  # 警告:读取为非原文
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号