Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
打印python类和函数的结果以将yahoo财务数据显示为行_Python_Python 3.x_Class_Yahoo Finance - Fatal编程技术网

打印python类和函数的结果以将yahoo财务数据显示为行

打印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

我正在尝试从雅虎财经获取股票价格,并将结果打印为,例如AAPL,163.05。我创建了一个类并定义了一些函数,但没有得到预期的结果。你能告诉我我做错了什么吗

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'