python 分割字符

测试小公举 / 2023-07-27 / 原文

#输入王小明,输出王 小明
#读取原始txt文件
with open('D:\\PCCW_Test_Script\\111.txt', encoding='utf-8') as file1:
    content = file1.readlines()
    # print(content)

with open('D:\\PCCW_Test_Script\\222.txt', "w", encoding='utf-8') as file2:
    for name in content:
        name=name.strip()
        name_parts = name[:1]+ str(" ")+ name[1:]
        # print(name_parts)
        file2.write(name_parts + '\n')