-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex16.py
More file actions
28 lines (19 loc) · 696 Bytes
/
ex16.py
File metadata and controls
28 lines (19 loc) · 696 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
from sys import argv
script, filename = argv
print(f'We are going to delete {filename}')
print('If you want to quit, hit CTRL-C(^C)')
print('If you want to continue, hit RETURN')
input("?")
print('Opening the file')
# file should be opened in write mode, thus pass 'w', else it will be opened in read mode by default
target = open(filename, 'w')
# as file is in write mode, you can not read it
# print(target.read())
print('You selected to truncate above file, deleting its contents now!')
target.truncate()
print('Lets add some content to the file')
line1 = input("line1: ")
line2 = input("line2: ")
line3 = input("line3: ")
target.write(line1+"\n"+line2+"\n"+line3+"\n")
target.close()