2021年4月10日星期六

Return a specific value from an API

I use this script to get crypto prices:

from pycoingecko import CoinGeckoAPI  import json    cg = CoinGeckoAPI()  response = cg.get_price(ids='bitcoin', vs_currencies='usd')  print(response)    token = response.get('bitcoin','')  print(token)  

and the output returned is:

{'bitcoin': {'usd': 60302}}

{'usd': 60302}

How can I get just the value 60302 instead of the full column?

https://stackoverflow.com/questions/67041335/return-a-specific-value-from-an-api April 11, 2021 at 11:59AM

没有评论:

发表评论