-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
67 lines (58 loc) · 2.08 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
print("Instructions:\nRefresh whole program after creating new file\nDelete or rename files manually\nDont rename Note.txt or delete the file\nType:\n\tclose = stop typing\n\tdelete = delete last line\n\tclear = delete all file contents\n\tchange = open another file\n")
f = open("Note.txt")
original = f.read()
print(original)
f.close()
new = input("")
currentfile = "Note.txt"
while new != "close":
if new == "delete":
delete = open(currentfile, 'rb')
pos = next = 0
for line in delete:
pos = next
next += len(line)
delete.close()
delete = open(currentfile, 'ab')
delete.truncate(pos-2)
delete.close()
print("")
print("")
delete.close()
delete = open(currentfile)
print(delete.read())
elif new == "clear":
clear = open(currentfile, "r+")
clear.truncate(0)
print("")
print("")
elif new == "new":
name = input("Enter name of file: ")
newfile = open(name + ".txt", "x")
currentfile = name + ".txt"
print("")
print("")
elif new == "change":
changeto = input("Change file to: ")
if changeto[-4:] != ".txt":
changeto = changeto + ".txt"
while os.path.exists(changeto) == False:
changeto = input("File doesn't exist. Change file to: ")
currentfile = changeto
print("")
print("")
changed = open(currentfile)
print(changed.read())
elif new == "instructions" or "instruction":
print("Instructions:\nRefresh whole program after creating new file\nDelete or rename files manually\nDont rename Note.txt or delete the file\nType:\n\tclose = stop typing\n\tdelete = delete last line\n\tclear = delete all file contents\n\tchange = open another file\n")
else:
add = open(currentfile, "a")
emptyfile = open(currentfile)
if emptyfile.read() == "":
add.write(new)
add.close()
else:
add.write("\n" + new)
add.close()
new = input("")