mirror of
https://github.com/Sosokker/Calculator-for-Matrix-and-Algebra.git
synced 2025-12-18 12:44:05 +01:00
Add read_history function to read history from history.json
This commit is contained in:
parent
c143c0ca2f
commit
9dd0dec3f9
@ -1,4 +1,5 @@
|
||||
import json
|
||||
from json import JSONDecodeError
|
||||
import os
|
||||
|
||||
def write_command(com, inp, out) -> None:
|
||||
@ -41,4 +42,16 @@ def delete() -> bool:
|
||||
os.remove("history.json")
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
return False
|
||||
|
||||
def read_history():
|
||||
filename = "history.json"
|
||||
try:
|
||||
with open(filename, "r") as file:
|
||||
number_dict = json.load(file)
|
||||
for line, data in number_dict.items():
|
||||
print(f" ({line}) Command: {data['command']} | Input: {data['input']} | Output: {data['output']}")
|
||||
except FileNotFoundError:
|
||||
raise FileNotFoundError("History file not found! Maybe program hasn't been saved yet.")
|
||||
except JSONDecodeError:
|
||||
print("History is empty.")
|
||||
Loading…
Reference in New Issue
Block a user