def parse_transaction_rc(file_name): print(f'parsing file "{file_name}"') budget = Budget.BudgetCategory() for i, line in enumerate(open(file_name).readlines()): key, value = line.split(':', 1) key = key.strip() if key[0:2] == '>>': # new budget -- handle previous handle_budget(budget) budget = Budget.BudgetCategory(value) else: description = value.strip() money = Money.Money(key) transaction = Money.Transaction(money, description) # TODO: add description & date budget.add_transaction(transaction) # handle last budget handle_budget(budget)
#statment A #import Budget #statment B #import Budget;print(calcBills()) #statment C import Budget print(Budget.calcBills()) #statment D
#QUIZ which one returns calculated bills on IDLE? import Budget import Budget; print(calcBills()) import Budget; print(Budget.calcBills()) ###THIS ONE
import Budget food = Budget.Budget("Food") food.deposit(1000, "Inital deposit") food.withdraw(120, "Meat and fish") print(food.balance()) clothing = Budget.Budget("Clothing") food.transfer(350, clothing) clothing.withdraw(50, "Hats") clothing.withdraw(170, "Shoes") rent = Budget.Budget("Rent") rent.deposit(4500, "Intial deposit") rent.deposit(200, "Electricity bill") print(rent) print("\n") print(food) print("\n") print(clothing)
import Budget;print(Budget.calcBills())
def create_budget(budget_name, reset_period_type, move_leftover): '''Create a budget object and then save it to a file.''' created_budget = Budget.Budget(budget_name, reset_period_type, move_leftover) save_budget(created_budget)
path = os.path.abspath(__file__) dirname, useless = os.path.split(path) ROOT_DIR = dirname + '/' DB_FILE_NAME = ROOT_DIR + 'ka.db' BACKUP_FILE_NAME = ROOT_DIR + 'commit.backup' logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) logger = logging.getLogger('ReloadAllData') service_list = {} service_list['account'] = Account.Account(logger) service_list['category'] = Category.Category(logger) service_list['record'] = Record.Record(logger) service_list['statistic'] = Statistic.Statistic(logger) service_list['budget'] = Budget.Budget(logger) service_list['currency'] = Currency.Currency(logger) # 删除数据库文件 if os.path.exists(DB_FILE_NAME): os.remove(DB_FILE_NAME) # 读取创建数据库SQL文件内容 f = open(ROOT_DIR + 'sql/create.sql', encoding='utf-8') create_sql_content = f.read() f.close() f = open(ROOT_DIR + 'sql/add_basic_data.sql', encoding='utf-8') add_basic_data_sql_content = f.read() f.close() # 重新创建数据库