-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnote.py
44 lines (37 loc) · 1010 Bytes
/
note.py
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
34
35
36
37
38
39
40
41
42
43
44
def action_note(a,file,m):
if(a=='add'):
write_note(file,m)
elif(a=='list'):
list_note(a,file)
elif(a=='remove'):
remove_note(file,m)
else:
print('Unknown Command called. Use add, remove or list')
def write_note(file,m):
with open(file,'a') as f:
print(m,file=f)
def list_note(a,file):
c=1
with open(file) as f:
l=[]
try:
for line in f:
l.append(line.strip())
except FileNotFoundError:
print('File name does not exist')
if(a=='list'):
for x in l:
print(f'{c}. {x}')
c+=1
else:
return l
def remove_note(file,m):
l=list_note('',file)
del l[int(m)-1]
with open(file,'w') as f:
for x in l:
print(x,file=f)
#write_note('hello.txt','kill me')
#list_note('list','hello.txt')
#remove_note('hello.txt',3)
#list_note('list','hello.txt')