January 2019
Beginner
318 pages
8h 23m
English
By using Python, you can create a text file (test.txt). By using the code, writing to a text file is easy. To open a file for writing, we set the second parameter that is in access mode to "w". To write the data into this test.txt file, we use the write() method of the file handle object. Create a script called text_write.py and write the following content in it:
text_file = open("test.txt", "w")text_file.write("Monday\nTuesday\nWednesday\nThursday\nFriday\nSaturday\n")text_file.close()
Run the preceding script and you will get the output as follows:
![]()
Now, check your current working directory. You'll find a test.txt file ...
Read now
Unlock full access