python write

Do you want to know the information regarding “python write”. If yes, you’re in the correct article.

python write

file = open(“testfile.txt”,”w”) 
file.write(“Hello World”) 
file.write(“This is our new text file”) 
file.write(“and this is another line.”) 
file.write(“Why? Because we can.”) 
#there are many modes you can open files in. r means read.
file = open('C:\Users\yourname\files\file.txt','r')
text =

#you can write a string to it, too!
file = open('C:\Users\yourname\files\file.txt','w')
file.write('This is a typical string')

#don't forget to close it afterwards!
fin = open("NAME.txt", 'r')
body ="\n")
line = fin.readline().strip()
# read, write, close a file
# catch error if raise
    file = open("tryCatchFile.txt","w") 
    file.write("Hello World")

    file = open("tryCatchFile.txt", "r")
except Exception as e:
print("This is where you put the message you want to write")


I hope this tutorial helps you to know about “python write”. If you have any doubts regarding this article please let us know via the comment section. Share this tutorial with your friends & family via social networks.

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coder Diksha. Here, I post about programming to help developers.

Share on:

Leave a Comment