Python создает систему транзакций, читая файлы json

#python

Вопрос:

Я работаю над проблемой

 def update_transactions(file_path: str, transaction_list: list):
"""
You are part of a team tasked to create an application that helps bankers by saving their transactions for them.
Your job within the project is to implement the feature that actually saves the transactions to the hard drive.
The scope of your task is that you will be given a file path to where the data should be written and a list of
bank transaction objects to be written to the file. The file will contain a JSON array of transactions that the
banker previously saved. The bankers at this bank are silly sometimes and they make duplicate transactions, your
function should remove the duplicate transactions in the transaction_list and update the existing transaction list
saved in the file with the new transactions. Make sure when you are preforming the update of the new transactions
that you overwrite old transactions (transactions that already exist in the file) with duplicate new transactions
(transactions that are found in the transaction_list). You will know that a transaction is a duplicate if it has
 the same ID.

In the end the file should contain a JSON list with transaction Objects that have been updated with the new
information from the transaction_list. The JSON list should contain no transactions with the same ID.

The transaction object referred to here in is outlined below. In actual testing of your code the professors
transaction object will be used, which will have all the documented functionality.

class Transaction:

    def __init__(self, id:int, type:str, amount:float):
        self.id:int = id
        self.type:str = type
        self.amount:float = amount

    def __str__(self):
        return 'Transaction[%s] %s $%s' (self.id, self.type, self.amount)

    def __hash__(self):
        return hash(self.id)

    def __eq__(self, other):
        return hasattr(other,'id') and other.id == self.id

:param file_path: A path to file blank file that holds a JSON list of existing transaction and where the new
 transaction data should be written
:param transaction_list: A list of transaction
:return: None
"""
 

Хотя я думаю, что у меня есть понимание чтения файлов json на Python, я боролся с этой проблемой в течение нескольких дней. Должен ли я открывать файлы JSON в самой первой части метода или создавать дополнительные методы для его решения?

Комментарии:

1. Является update_transactions() ли данная функция для реализации или чем-то вашим собственным творением? Если задано ,тип для transaction_list -это список, что означает, что он уже должен быть в формате списка коллекций ключей и значений. JSON обычно представляется в виде строки. Кроме того, в __str__(self) методе отсутствует знак процента (%) между строкой и кортежем.

2. Однако, если вы импортируете данные из файла, вы можете попробовать json.load из стандартной библиотеки для импорта и обработки данных перед их обработкой.

3. @MarkMoretto Я должен реализовать метод update_transactions() для выполнения задачи, написанной в комментарии