I have the following code, which is a function to export a transaction history from a digital currency wallet to a json file.
The problems I am facing are two:
I would like to allow the json file to be written in utf-8, as the property 'label' can be utf-8 characters, and if I do not account for that, it will show up in the file as \u\u\u etc. However, no matter what combinations and orderings of encode/decode('utf-8'), I can not get the final output file to print to utf-8.
I would like to order each iteration in the order I wrote them in the code. I tried OrderedDict from collection, but it did not order the items so that Date comes first, etc.
Any help with figuring out how to print this to my file using utf-8 and with the order inside each item as I wrote it.
Thank you very much.
# This line is the last line of a for loop iterating through
# the list of transactions, "for each item in list"
wallet_history.append({"Date": time_string, "TXHash": tx_hash, "Label": label, "Confirmations":
confirmations, "Amount": value_string, "Fee": fee_string, "Balance": balance_string})
try:
history_str = json.dumps(
wallet_history, ensure_ascii=False, sort_keys=False, indent=4)
except TypeError:
QMessageBox.critical(
None, _("Unable to create json"), _("Unable to create json"))
jsonfile.close()
os.remove(fileName)
return
jsonfile.write(history_str)