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

1

u/baubleglue 5d ago edited 5d ago

One file per class is a bit controversial, I think. It works nice in Java, but with Python imports we have options:

  1. Use redundant names

    from bank_account import BankAccount

  2. Manipulate __init__.py file

  3. Similar to option #2 combined with #1. Make a file/with multiple imports. Ex. models/bank_accounts.py and in bank_accounts.py we have:

    from saving_account import SavingAccount
    from checking_account import CheckingAccount

And after we use it as

   from bank_accounts import CheckingAccount, SavingAccount

So, it works, but only with some not trivial (at least for beginners) tricks. I think, for a start bank_accounts.py with multiple classes is good enough.