打印python类和函数的结果以将yahoo财务数据显示为行
我正在尝试从雅虎财经获取股票价格,并将结果打印为,例如AAPL,163.05。我创建了一个类并定义了一些函数,但没有得到预期的结果。你能告诉我我做错了什么吗打印python类和函数的结果以将yahoo财务数据显示为行,python,python-3.x,class,yahoo-finance,Python,Python 3.x,Class,Yahoo Finance,我正在尝试从雅虎财经获取股票价格,并将结果打印为,例如AAPL,163.05。我创建了一个类并定义了一些函数,但没有得到预期的结果。你能告诉我我做错了什么吗 from yahoo_finance import Share class YahooFinance(): def Prices(self, symbol): price = Share(symbol).get_price() #print(price) def Change(self, s
from yahoo_finance import Share
class YahooFinance():
def Prices(self, symbol):
price = Share(symbol).get_price()
#print(price)
def Change(self, symbol):
change = Share(symbol).get_change()
#print(change)
def pClose(self, symbol):
pclose = Share(symbol).get_prev_close()
#print(pclose)
def tDateTime(self, symbol):
tdatetime = Share(symbol).get_trade_datetime()
#print(tdatetime)
你的方法中没有返回任何内容。因此,将您的方法重写为:
def Prices(self, symbol):
return Share(symbol).get_price()
YahooFinance().Prices('AAPL')
'163.05'
def Prices(self, symbol):
return Share(symbol).get_price()
YahooFinance().Prices('AAPL')
'163.05'