Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I print a specific attribute from a function?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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'])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading