Facebook
From Torrid Mockingbird, 7 Months ago, written in Python.
This paste is a reply to nauka, konstruktory destruktory from Maciej Salwa - view diff
Embed
Download Paste or View Raw
Hits: 111
  1. class Account:
  2.     def __init__(self, filepath):
  3.         self.filepath = filepath
  4.         with open(filepath, 'r') as file:
  5.             self.balance=int(file.read())
  6.  
  7.     def withdraw(self, amount):
  8.         self.balance = self.balance - amount
  9.  
  10.     def deposit(self, amount):
  11.         self.balance = self.balance + amount
  12.  
  13.     def __del__(self):
  14.         print("self.filepath wynosi:", self.filepath)
  15.         print("self.balance wynosi wynosi:", self.balance, "i ma typ:", type(self.balance))
  16.         with open(self.filepath, 'w') as file:
  17.             file.write(str(self.balance))
  18.  
  19. account = Account("balance.txt")
  20. print("na koncie jest:", account.balance)
  21. account.withdraw(100)
  22. print("na koncie jest:", account.balance)
  23. del(account)
  24. # account.commit()