import re

input_file = "input.txt"  # 输入文件路径
output_file = "output.txt"  # 输出文件路径



#  判断字符属于中文还是英文
def is_chinese_char(ch):
    if u'\u4e00' <= ch <= u'\u9fff':
        return True
    elif u'\u0041' <= ch <= u'\u005a' or u'\u0061' <= ch <= u'\u007a':
        return False
    else:
        return None
# 打开输入文件和输出文件
with open(input_file, "r", encoding="utf-8") as f_input, open(output_file, "w", encoding="utf-8") as f_output:
    # 逐行读取输入文件
    for line in f_input:

        for char in line:
            if is_chinese_char(char):
                new_char = char + ' '
                print(new_char,end='')
            else:
                new_char = char
                print(new_char,end='')

            f_output.write(new_char)


# 提示处理完成
print("文本处理完成!")

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐