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

F735_T1971_YYH · December 29, 2021 · 287 hits

测试读取 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('系统报告:可正常读取')  # 警告:读取为非原文
No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.