-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfile_append.py
More file actions
29 lines (22 loc) · 841 Bytes
/
Copy pathfile_append.py
File metadata and controls
29 lines (22 loc) · 841 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
"""
Shows how to append to a file using the file object's write() method.
"""
def main():
"""
A simple method to open a file and append a few lines to it.
"""
f = open("./data/jabberwocky.txt", "a") # open the file in append mode
print("\Appending new lines to the file...\n")
f.write('"Beware the Jabberwock, my son!\n')
f.write("The jaws that bite, the claws that catch!\n")
f.write("Beware the Jubjub bird, and shun\n")
f.write('The frumious Bandersnatch!"\n')
f.write(
"\nRead the entire poem: https://www.poetryfoundation.org/poems/42916/jabberwocky\n"
)
# when done, always close the file
f.close()
# ------------------------------------------------------------ #
# If this file is being run directly, call the main method ... #
if __name__ == "__main__":
main()