This article mainly introduces examples of adding spaces after each character in python. It has certain reference value. Now I share it with you. Friends in need can refer to it
The example is as follows:
#!/usr/bin/env Python # coding=utf-8 file = open("chinese1.txt",'r') file2 = open(r'chinese2.txt', 'w')# 返回一个文件对象 list1= file.readlines() list2 = [] j = -1 for i in list1: j+=1 if j % 3 == 2: list1[j] = ("=== \n") else: list1[j] = i # print(j) # print(list1[j]) for i in list1: file2.write(i) file.close() file2.close() file = open(r'two_1_2.0_100w.txt', 'r') file2 = open(r"chinese1.txt",'w') file2.write(' '.join([f+ ' ' for fh in file for f in fh ])) file.close() file2.close()
Related recommendations:
Solve the problem of encoding socks5 proxy in Python requests library
The above is the detailed content of Python example of adding spaces after each character. For more information, please follow other related articles on the PHP Chinese website!