Skip to content
Discussion options

You must be logged in to vote

Good edge-case hunting — as written, a task name containing | silently loses the task. save_tasks() writes "pay bob|True" as pay bob|True (with the embedded bar), but load_tasks() splits on every |, gets 3 parts, fails the len(parts) == 2 check, and drops the line without a word. Data loss with no warning is the worst failure mode here.

Two fixes, in increasing order of "right":

1. Split from the right, not the left. The status is always the last field, and it's only ever the literal True/False, so the separator is unambiguous if you anchor it:

task_name, done_status = line.rstrip("\n").rsplit("|", 1)
todo_list.append({"task": task_name, "done": done_status == "True"})

This survives any n…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dab00gieman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants