Python Forum
ATM machine (deposits/withdrawals) using OOP
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ATM machine (deposits/withdrawals) using OOP
#16
property is not a reserved word. Is is a function. for is a reserved word. while is a reserved word. property is a useful function (and @decorator) in builtins. You can repurpose function names, they are just variables, but that eliminates using the original function.

If you reuse a builtin name inside a function the effect is highly localized and not likely a problem. The builtin cannot be used inside the function. If you reuse a builtin name in global scope it means you would have to use a scope specifier to use the original. This is questionable at best.
print = lambda x: __builtins__.print("I have a bad feeling about this", x)
print("Chewy")
Output:
I have a bad feeling about this Chewy
If you replace the function in the builtins scope there is a special level in hell reserved just for you. The original is no longer accessible.

is_dunder() does not work for properties, or attributes, or objects, unless that object is a str. dir() returns a list of strings, so is_dunder(x) expects x to be a str. By itself is_dunder() isn't particularly interesting, it is a helper function. I would rewrite print_properties() as:
def print_properties(obj):
    """Print non-dunder properties of obj.  Does not do bad things like using a list comprehension for it's side effect]"""
    print("\n".join([f"{p}={getattr(obj, p)}" for p in dir(obj) if not p.startswith("__")]))
I'm not sure what knackwurstbagel has against dunders. If you want to know the attributes inside an object, __dict__ works better than dir(). dir() is just attribute names, and lots of names. __dict__ is a dictionary of attributes (names and values) for the object. The stuff you are most interested in.
class Me():
    def __init__(self):
        self.x = 1
        self.y = 2

m = Me()
print(m.__dict__)  # Get this for free
print_properties(m)  # Have to remember to import
Output:
{'x': 1, 'y': 2} x 1 y 2}
I think having transactions print anything is a bad idea, and that printing the "transaction" is particularly egregious. Instead of printing, transactions should return a transaction id object. The transaction would have the account number, transaction type, balance and transaction id and transaction date/time. You can print the transaction object or not. You can add the transaction to a list to have a transaction history. Transactions should only have one side effect (at most), and that is changing the balance.
Reply


Messages In This Thread
RE: ATM machine (deposits/withdrawals) using OOP - by deanhystad - Mar-14-2022, 11:12 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020