Jun-13-2023, 05:12 PM
Hi, in scripts 1 and 2 below I got different behavior on object yf.Ticker.
Script 1 runs fine and in fact so too did a similar Script 2 for a moderator from this forum. But on my PC, Script 2 generates the attribute error you see in item 3. I did learn that I can just set ticker to line.strip("\n\r") but I think I want to understand the attribute error anyway.
Script 1 runs fine and in fact so too did a similar Script 2 for a moderator from this forum. But on my PC, Script 2 generates the attribute error you see in item 3. I did learn that I can just set ticker to line.strip("\n\r") but I think I want to understand the attribute error anyway.
import yfinance as yf import sys for line in open('C:\\Users\\stant\\OneDrive\\Documents\\daxandpython\\tickers.txt'): tkr=yf.Ticker(line.strip("\n\r")) with open('C:\\Users\\stant\\OneDrive\\Documents\\daxandpython\\yfinance\\'+line.strip("\n\r") +'.txt', 'w') as sys.stdout: tkr.history(period="max")
import yfinance as yf import pandas as pd #import sys from datetime import date today = date.today() data = None for line in open('C:\\Users\\stant\\OneDrive\\Documents\\daxandpython\\tickers.txt'): ticker=yf.Ticker(line.strip("\n\r")) x = yf.download(ticker, start="2017-01-01", end=today, progress=False).round(2) #x["Stock"]=ticker x.insert(0, "Ticker", ticker) if data is None: data = x else: data = pd.concat((data, x)) data = data.sort_index()
Error:Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "C:\Users\stant\AppData\Local\Programs\Python\Python311\Lib\site-packages\yfinance\multi.py", line 107, in download
tickers, (list, set, tuple)) else tickers.replace(',', ' ').split()
^^^^^^^^^^^^^^^
AttributeError: 'Ticker' object has no attribute 'replace'