Demonstrates writing to a text file : Text File Write « File « Python






Demonstrates writing to a text file

Demonstrates writing to a text file
# 

print "Creating a text file with the write() method."
text_file = open("write_it.txt", "w")
text_file.write("Line 1\n")
text_file.write("This is line 2\n")
text_file.write("That makes this line 3\n")
text_file.close()



           
       








Related examples in the same category

1.Reading the newly created file.Reading the newly created file.
2.Creating a text file with the writelines() method.Creating a text file with the writelines() method.
3.Write string to a file