Answer to Question #231130 in Python for Rachna Pal

Question #231130

Write a program in Python allowing to delete multiple spaces in a text file

named myfile.txt which contains a text: T =

'Python is programming language'


1
Expert's answer
2021-09-04T15:22:55-0400
import os
# opening file in read mod
file = open("myfile.txt" , "r")

# retrieving the file content in string type
content = file.read()
file.close()
# converting the string content to a list
L = content.split() 

# opening the file in write mod by overwriting its content
file = open("myfile.txt" , "w")

# browsing through list items
for word in L:
    file.write(word + " ")
file.close()
os.startfile('myfile.txt')

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