Answers for "write a file with content python"

75

python write to file

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.”) 
 
file.close() 
Posted by: Guest on December-09-2019
0

open and write in a file in python

my_file = open("C:\Users\Python\file.txt", "w")
#Give the path accurately and use \
my_file.write("This is the test text")
my_file.close()

# It is always recommended to close the file after modifying
# to see the output, open the file - file.txt
Posted by: Guest on January-06-2022

Python Answers by Framework

Browse Popular Code Answers by Language