python 'yfinance‘模块在熊猫数据中下载许多金融证券的报价,同时在控制台中显示一个进度条。以这种方式:
import yfinance as yf
Tickerlist = ["AAPL","GOOG","MSFT"]
quote = yf.download(tickers=Tickerlist,period='max',interval='1d',group_by='ticker')
我想实时捕获控制台进度栏,代码应该如下:
import sys
import subprocesss
process = subprocess.Popen(["yf.download","tickers=Tickerlist","period='max'","interval='1d'","group_by='ticker'"],stdout=quote)
while True:
out = process.stdout.read(1)
sys.stdout.write(out)
sys.stdout.flush()
我把子进程弄得一团糟。我需要你的帮助!谢谢。我已经看到了处理这个话题的所有链接,但没有能够解决我的问题。
发布于 2019-12-23 14:39:37
您需要两个python文件来做您想做的事情。
一个是yf_download.py,第二个是run.py
文件代码如下所示,您可以通过run.py运行它
python run.py
yf_download.py
import sys
import yfinance as yf
Tickerlist = ["AAPL","GOOG","MSFT"]
def run(period):
yf.download(tickers=Tickerlist, period=period,interval='1d',group_by='ticker')
if __name__ == '__main__':
period = sys.argv[1]
run(period)
run.py
import sys
import subprocess
process = subprocess.Popen(["python", "yf_download.py", "max"],stdout=subprocess.PIPE)
while True:
out = process.stdout.read(1)
if process.poll() is not None:
break
if out != '':
sys.stdout.buffer.write(out)
sys.stdout.flush()
https://stackoverflow.com/questions/59456868
复制相似问题