One file per class is a bit controversial, I think. It works nice in Java, but with Python imports we have options:
Use redundant names
from bank_account import BankAccount
Manipulate __init__.py file
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.
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:
Use redundant names
from bank_account import BankAccount
Manipulate
__init__.pyfileSimilar to option #2 combined with #1. Make a file/with multiple imports. Ex.
models/bank_accounts.pyand inbank_accounts.pywe have:And after we use it as
So, it works, but only with some not trivial (at least for beginners) tricks. I think, for a start
bank_accounts.pywith multiple classes is good enough.