-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathprog16_File_Writing.py
More file actions
30 lines (26 loc) · 899 Bytes
/
prog16_File_Writing.py
File metadata and controls
30 lines (26 loc) · 899 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
# Open file in write mode
# f = open("ram2.txt", "w")
# f.write("I am 30 years old.")
# f.close()
# """
# This will open ram2.txt file and replace all the contents.
# But If file does not exists then it will create new file and replace all the contents.
# """
# Open file in append mode
# f = open("ram3.txt", "a")
# f.write("My DOB is 2-Jan-1987.\n")
# f.close()
# """
# This will open ram2.txt file and add the contents at end of the file.
# But If file does not exists then it will create new file add the contents at end of the file.
# """
# Add contents in file and print no of charector
# f = open("ram2.txt", "a")
# i = f.write("Ram is a good boy.\n")
# print(i) # This will print total no of char of i
# f.close()
# Handle read and write mode
f = open("ram3.txt", "r+")
print(f.read()) # read operation
f.write("Thanks you.\n") # write operation
f.close()