打印我的 python class & 函数的结果以将雅虎财务数据显示为行

Printing the result of my python class & function to show yahoo finance data as rows

我正在尝试从 Yahoo-finance 获取股票价格并将结果打印为“,”分隔(例如 AAPL,163.05)。我创建了一个 class 并定义了一些函数,但我没有得到想要的结果。你能告诉我我做错了什么吗?

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)

>>> print(YahooFinance().Prices('AAPL'))
None
>>> Share('AAPL').get_price()
'163.05'

您没有在方法中返回任何内容。因此,将您的方法重写为:

def Prices(self, symbol):
        return Share(symbol).get_price()

YahooFinance().Prices('AAPL')
'163.05'