【发布时间】:2021-09-09 08:56:26
【问题描述】:
我正在尝试根据市值过滤股票,并且我想将股票列表设置为类对象,因此我将带有股票代码的数组作为对象传递。但是当我期望它返回两个布尔值(因为有两只股票)时,我只得到一个“假”。
如何修改以下代码,以便获取列表中所有项目的 cond_1 属性。 (例如 AAPL.cond_1 = False,GOOG.cond_1 = False)?
top_gainer_list = ['AAPL', 'GOOG']
class gainers():
def __init__(self, cond_1):
self.cond_1 = cond_1
def filter_marketCap(self):
backup_list1 = []
iexresponse = requests.get(
"https://cloud.iexapis.com/stable/stock/market/batch?symbols={}&types=quote&token=APIKEY".format(
','.join(top_gainer_list)))
data = iexresponse.json()
for ticker in top_gainer_list:
marketCap = int(data[ticker]['quote']['marketCap'])
if 10000000 <= marketCap <= 200000000:
self.cond_1 = True
else:
self.cond_1 = False
top_gainer = gainers(top_gainer_list)
top_gainer.filter_marketCap()
print(top_gainer.cond_1)
【问题讨论】:
标签: python arrays class object oop