我正在将yfinance中的股票代码拉到一个列表中并尝试打印列表。打印时,列表打印时会向每个股票代码添加字符。我想删除这些字符并尝试使用lstrip
和rstrip
函数,但我继续获得添加的字符。下面是输入代码:
for i in edited_buylist:
i = str(i)
i = i.lstrip('yfinance.Ticker object <')
for i in edited_buylist:
i = str(i)
i = i.rstrip('>')
print("The list of securities that are at or near support points are: ", str(edited_buylist))
下面是该代码的输出:
The list of securities that are at or near support points are: [yfinance.Ticker object <VVV>]
'''
我想删除"yfinance。股票代码对象<"和">"。
您可以使用ticker
属性:
edited_buylist = [i.ticker for i in edited_buylist]
print("The list of securities that are at or near support points are: ", str(edited_buylist))