from sortedcontainers import SortedDict
buffer = SortedDict({})
while True:
inp = input(">> ")
parts = inp.split(" ")
if len(parts) == 0:
continue
if parts[0].isnumeric():
num = int(parts[0])
buffer[num] = " ".join(parts[1:])
elif parts[0] == "list":
for key in buffer.keys():
print(f"{key}: {buffer[key]}")
elif parts[0] == "save":
file = open(parts[1], "w")
for key in buffer.keys():
file.write(buffer[key] + "\n")
print("saved")
elif parts[0] == "open":
file = open(parts[1], "r")
lineNum = 10
for line in file:
buffer[lineNum] = line.rstrip()
lineNum += 10
else:
print(f"Unknown command {parts[0]}")
post a comment