-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.py
More file actions
40 lines (39 loc) · 1.2 KB
/
file.py
File metadata and controls
40 lines (39 loc) · 1.2 KB
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
import time
try:
fname="notebook.txt"
handler=open(fname,"r")
except IOError:
handler=open(fname,"a")
print("No default notebook was found, created one.")
while True:
print("Now using file",fname,"\n(1) Read the notebook\n(2) Add note\n(3) Empty the notebook\n(4) Change the notebook\n(5) Quit\n")
choice=int(input("Please select one:"))
if choice==1:
handler=open(fname,"r")
content=handler.read()
print(content)
handler.close()
elif choice==2:
handler=open(fname,"a")
text=input("write a new note:")
date=time.strftime("%X %x")
text=text+":::written on/at "+date+"\n"
handler.write(text)
handler.close()
elif choice==3:
handler=open(fname,"w")
handler.close()
print("Notes deleted.")
elif choice==4:
fname=input("Give the name of the new file:")
try:
handler.close()
handler1=open(fname,"r")
except IOError:
handler1=open(fname,"a")
print("No notebook with that name detected, created one.")
elif choice==5:
print("Notebook shutting down, thank you.")
break
else:
print("Incorrect selection")