r/PythonLearning • u/AbdulRehman_JS • 16h 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.....)
1
u/mc_pm 15h ago
This is great, but just a bit of a warning that you aren't even close to "mastered core Python basics and modular structure". This is a fun little project, and I don't want you to think this wasn't an accomplishment because it definitely is. But you are just starting your journey.
1
u/AbdulRehman_JS 15h ago edited 14h ago
Thanks! bro now i understood what i do but a little problem how i can learn "mastered core Python basics and modular structure"...
1
u/mc_pm 8h ago
Practice. Build something more complicated, learn from it; build something even more complicated, learn from it; and keep going. You can start with this, though. How can you get it to delete old todo items?
1
u/AbdulRehman_JS 6h ago
Ohh! I understood... I thought that "mester core python basics and modular structure" is another chapter or topic in python like list comprehension😆😆😆😆.... thanks for clearify.. now i quiet understood... I decide to built a scientific calculator..
1
u/FoolsSeldom 7h ago
mastered core Python basics
I assume you are joking.
You need to consolidate the basics into a more complex project with a more sophisticate UI and UX.
How about:
- Creating a menu class
- make it easy to add menu entries
- present menu
- validate option
- return the call to use to fulfil the chosen option
- Update the menu to support multiple languages
- Ensure logic is separate from presentation
- Create a basic tkinter (desktop gui) version
- OPTIONAL: (additional package) Create a modern browser gui version (e.g. using NiceGUI)
- Switch from basic file to a SQL database using sqlite initially
- Add task updating / progress tracking / reporting / assignment
- and so on
1
u/AbdulRehman_JS 6h ago
ohh! first i am serious about "mastered core Python basics and modular structure". I thought it like a chapter or topic😁😁😁.. thanks in this message i realize.. and Bridging the basics into a full DB-driven UI app sounds like a great exercise. it's a good advice thanks.. i built it first and then go to another project.. give me idea about scientific calculator.... like it's module etc... and thanks for clearify......
1
u/FoolsSeldom 6h ago
You might find it more productive to focus on projects related to your personal interests / hobbies / side-hustles / family obligations / etc. Anything you can be passionate about and have a good understanding of (or incentive to develop that interest in).
When working on such things, you have the advantage of having a clear understanding of the problems you are trying to solve, what the constraints are, what outcomes are required, and so on.
Typically, you learn faster and more deeply on this basis. You pick up what you need to when you need to because you are more focused on the problem you are solving rather than the technology involved.
•
u/Sea-Ad7805 13h 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.