2 回答
TA贡献1798条经验 获得超7个赞
您需要将变量设为quotesArr全局变量,将其放在函数之外并在完成后编写 json。
quotesArr = []
def convertToJson(quote_name,quote_price,quote_volume):
quoteObject = {
"Name": quote_name,
"Price": quote_price,
"Volume": quote_volume
}
quotesArr.append(quoteObject)
def trendingBot(url, browser):
browser.get(url)
trending = getTrendingQuotes(browser)
for trend in trending:
getStockDetails(trend, browser)
# requests finished, write json to file
with open('trendingQuoteData.json', 'w') as outfile:
json.dump(quotesArr, outfile)
TA贡献1848条经验 获得超2个赞
import json
a = json.loads(jsonStringA)
b = json.loads(jsonStringB)
c = dict(a.items() + b.items())
# or c = dict(a, **b)
添加回答
举报