Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
531 views
in Technique[技术] by (71.8m points)

python - IndentationError is it tabs and spaces

i keep getting this error and i have no idea why IndentationError: unindent does not match any outer indentation level, i think it has something to do with spaces and tabs but im not to sure

import urllib2
import time
import json
import random

# Server API URLs
QUERY = "http://localhost:8080/query?id={}"

# 500 server request
N = 1


def getDataPoint(quote):
    stock = quote['stock']
    bid_price = float(quote['top_bid']['price'])
    ask_price = float(quote['top_ask']['price'])
    price = (bid_price+ask_price)/2
    return stock, bid_price, ask_price, price

def getRatio(price_ratio):
  price_a = float(price_ratio['price_a']['price'])
  price_b = float(price_ratio['price_b']['price'])

  return price_a, price_b


# Main
if __name__ == "__main__":

    # Query the price once every N seconds.
    for _ in xrange(N):
        quotes = json.loads(urllib2.urlopen(QUERY.format(random.random())).read())

        """ ----------- Update to get the ratio --------------- """
        for quote in quotes:
            stock, bid_price, ask_price, price = getDataPoint(quote)
            print "Quoted %s at (bid:%s, ask:%s, price:%s)" % (stock, bid_price, ask_price, price)
    price_a , price_b = getRatio(price_ratio)
        print "Ratio %s" % (price_a, price_b)
question from:https://stackoverflow.com/questions/65843469/indentationerror-is-it-tabs-and-spaces

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...