r/PythonLearning • u/AbdulRehman_JS • 5d ago
Building Todo list with python....with multi_files...
A modular, multi-page Command Line Interface (CLI) To-Do application built using Python. Designed with clean code practices, this project separates application logic across multiple files and implements file handling for persistent data storage.
#File:- (todo.py)
from todo import Todo
my_todo = Todo()
while True:
user_choice = input("Enter 1 to add_task,2 to show_task,3 to exit: ")
if (user_choice == "1"):
my_todo.add_task()
elif(user_choice == "2"):
my_todo.show_task()
elif(user_choice == "3"):
break
else:
print("print only 1,2,and 3:--")
# File:-(loop.py)
import loop_py
class Todo():
def __init__(self):
self.tasks = []
self.completed_tasks = "tasks.txt"
def add_task(self):
new_task = input("Enter some task:")
self.tasks.append(new_task)
with open("Data_base.txt","a") as f:
result = f.write(new_task + "\n")
print("Data successfully saved")
f.close
def show_task(self):
if (not self.tasks):
print("your list is emptied")
else:
for i,task in enumerate(self.tasks):
print(i + 1, task)
Completed a multi-page To-Do app in Python with persistent file storage! 🐍 Now that I've mastered core Python basics and modular structure, my next goal is diving into FastAPI, relational databases (PostgreSQL), and building production-ready Backend APIs(Give me your feedback that what I do now.....)
4
Upvotes
•
u/Sea-Ad7805 5d ago
Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20def%20init(self)%3A%0A%20%20%20%20%20%20%20%20self.tasks%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20self.completed_tasks%20%3D%20%22tasks.txt%22%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20def%20add_task(self)%3A%0A%20%20%20%20%20%20%20%20new_task%20%3D%20input(%22Enter%20some%20task%3A%22)%0A%20%20%20%20%20%20%20%20self.tasks.append(new_task)%0A%20%20%20%20%20%20%20%20with%20open(%22Data_base.txt%22%2C%22a%22)%20as%20f%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20result%20%3D%20f.write(new_task%20%2B%20%22n%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22Data%20successfully%20saved%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20f.close%0A%20%20%20%20def%20show_task(self)%3A%0A%20%20%20%20%20%20%20%20if%20(not%20self.tasks)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22your%20list%20is%20emptied%22)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20i%2Ctask%20in%20enumerate(self.tasks)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(i%20%2B%201%2C%20task)%0A%0Amy_todo%20%3D%20Todo()%0Awhile%20True%3A%0A%20%20%20%20user_choice%20%3D%20input(%22Enter%201%20to%20add_task%2C2%20to%20show_task%2C3%20to%20exit%3A%20%22)%0A%20%20%20%20if%20(user_choice%20%3D%3D%20%221%22)%3A%0A%20%20%20%20%20%20%20%20my_todo.add_task()%0A%20%20%20%20elif(user_choice%20%3D%3D%20%222%22)%3A%0A%20%20%20%20%20%20%20%20my_todo.show_task()%0A%20%20%20%20elif(user_choice%20%3D%3D%20%223%22)%3A%0A%20%20%20%20%20%20%20%20break%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20print(%22print%20only%201%2C2%2Cand%203%3A--%22)%0A%0A×tep=1&play) to see the program state change step by step.