Home > OS >  How do I print a specific attribute from a function?
How do I print a specific attribute from a function?

Time:08-17

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?

CodePudding user response:

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'])
  • Related