How do I print a specific attribute from a function?

Question:

I am trying to use python to generate btc payments using BTCPay.

new_invoice = client.create_invoice({"price": 20, "currency": "USD"})
print(new_invoice)
f.close()

The output looks like this.

{'url': 'https://btc.url', 'posData': None, 'status': 'new', 'btcPrice': '0.00083344', 'btcDue': '0.00083344', 'cryptoInfo': [{'paymentUrls': {'BIP21': 'bitcoin:

How do I print specifically the ‘url’: or the bitcoin:{address} only? Instead of the entire string?

Asked By: Ace

||

Answers:

The type of your output is a dictionary with keys.
So, you can see your dictionary has a key of ‘url’: ‘https://btc.url’ which means that that url is assigned to that key. You can do this with all keys in your dictionary
We can grab this data by doing this

print(new_invoice['url'])
Answered By: Zachary
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.