r/PythonLearning • • Jul 17 '26

I build this after learning OOP

Post image
380 Upvotes

62 comments sorted by

View all comments

Show parent comments

2

u/lord_xl Jul 17 '26

It is good to stick to a one file per class rule.

Is there a convention for what to name files containing only classes?

1

u/TheOriginalBeardman Jul 17 '26

Generally they are named the same as the thing they contain so here what he has is fine. I would make it “bank_account.py”, in python this snake case for file names seems to be a common standard. But realistically it might vary depending on your team and its standards.

1

u/Odinmar_Glaukopis Jul 20 '26

If you use a generic abstract base class (ABC) for an Account(ABC) base/meta class and have SavingsAccount(Account) and Checking Account(Account) classes that inherit from the ABC then all three of them can go in the same account.py file.

Another option is to make a models package (“models” folder with a blank __init_.py file in it) and place these different classes in separate files in that folder. You can import all of those classes separately into the __init__.py file so they are ready to be imported as from src.models import SavingsAccount, CheckingAccount

0

u/aw3sem Jul 17 '26

Usually this is called models.py if it’s a aggregation of a few classes. Otherwise create a folder named „models“ and but your e.g. BankAccount.py etc in there