Write a python function to replace all the blank space in a file with star(*) and store the output in a new file. Note use regular expressions
# python 3.9.5
import re
with open('test.txt') as f:
lines = f.readlines()
f = open("new_file.txt", "w+")
for i in lines:
i = re.sub(' ', '*', i)
f.write(i)
f.close()
Comments
Leave a comment