Answer to Question #285781 in Python for adi

Question #285781

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 


1
Expert's answer
2022-01-09T10:44:46-0500
# 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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS