Mega Code Archive

 
Categories / Python / File
 

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()