-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_it.197.py
More file actions
33 lines (25 loc) · 774 Bytes
/
write_it.197.py
File metadata and controls
33 lines (25 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#Write It
# Demonstrates writing to a text file
# pg 197
print('Creating a text file with the write() method')
text_file = open("write_it.197.txt", "w")
text_file.write("Line1\n")
text_file.write("This is line2\n")
text_file.write("That makes this line 3\n")
text_file.close()
print("\nReading the newly created file.")
text_file = open("write_it.197.txt", "r")
print(text_file.read())
text_file.close()
print('\nCreating a text file with the writelines() method.')
text_file = open("write_it.198.txt", "w")
lines = ["Line1\n",
"This is line2\n",
"That makes this line 3\n",
]
text_file.writelines(lines)
text_file.close()
print("\nReading the newly created file.")
text_file = open("write_it.198.txt", "r")
print(text_file.read())
text_file.close()