Re: Import Json web data source to xls or csv

Discussion in 'Python' started by rusi, Feb 21, 2013.

  1. rusi

    rusi Guest

    On Feb 20, 6:54 am, Michael Herman <> wrote:
    > First - you can use Python in Excel.http://www.python-excel.org/orhttps://www.datanitro.com/
    >
    > Updated code:
    >
    > import json
    > import urllib
    > import csv
    >
    > url = "http://bitcoincharts.com/t/markets.json"
    > response = urllib.urlopen(url);
    > data = json.loads(response.read())
    >
    > f = open("bitcoin.csv","wb")
    > c = csv.writer(f)
    >
    > # write headers
    > c.writerow(["Currency","Symbol","Bid", "Ask", "Volume"])
    >
    > for d in data:
    >
    > c.writerow([str(d["currency"]),str(d["symbol"]),str(d["bid"]),str(d["ask"]),str(d["currency_volume"])])




    Looks neat.
    Tried it with and without the str and there are small differences.

    Why do you use the str?
     
    rusi, Feb 21, 2013
    #1
    1. Advertising

  2. rusi

    Peter Otten Guest

    rusi wrote:

    > On Feb 20, 6:54 am, Michael Herman <> wrote:
    >> c = csv.writer(f)
    >> c.writerow([str(d["currency"]),str(d["symbol"]),str(d["bid"]),
    >> str(d["ask"]),str(d["currency_volume"])])


    > Tried it with and without the str and there are small differences.


    The actual differences: float values are converted using repr() instead of
    str(), None values are converted to the empty str "".
    Both special cases make sense to me. So

    > Why do you use the str?
     
    Peter Otten, Feb 21, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vasudevram
    Replies:
    0
    Views:
    312
    vasudevram
    Aug 19, 2006
  2. Florian Frank
    Replies:
    0
    Views:
    244
    Florian Frank
    Jun 30, 2009
  3. sajuptpm
    Replies:
    2
    Views:
    346
    sajuptpm
    Dec 28, 2012
  4. Cousin Stanley
    Replies:
    1
    Views:
    114
    pyplexed
    Feb 20, 2013
  5. Michael Herman
    Replies:
    0
    Views:
    179
    Michael Herman
    Feb 20, 2013
Loading...

Share This Page