Creating a text file with the writelines() method. : Text File Write « File « Python






Creating a text file with the writelines() method.

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



           
       








Related examples in the same category

1.Demonstrates writing to a text fileDemonstrates writing to a text file
2.Reading the newly created file.Reading the newly created file.
3.Write string to a file