我是Python的初学者,正在尝试编写一个函数。
对于符号,我有一个要从数据库中获取的列表
cur.execute("SELECT sym FROM data")
list = cur.fetchall() ####fetches list from database column
[['AAPL'] ####This is the output of list
['MSFT']
['GOOGL']
['TSLA']
['AMZN']
['FB']
['V']
['BABA']
['WMT']]
如何为以下功能在符号中传递此列表的值?
symbol =
url_cf = 'https://somewebsite.com' + symbol
def scrape_data():
def dir_create():
# base dir
_dir = "/Users/Desktop/Companies"
# create dynamic name
_dir2 = os.path.join(_dir,symbol)
# create 'dynamic' dir,if it does not exist
if not os.path.exists(_dir2):
os.makedirs(_dir2)
dir_create()
# Scraping Cash Flow
def cash_flow():
.
.
page = requests.get(url_cf,headers)
.
.
#### Some function for scraping
.
.
path = '/Users/Desktop/Companies' + '/' + symbol
sheet_name = str('cash_flow_' + symbol + '.xlsx')
.
.
cash_flow()
scrape_data()
我希望对列表中的每个符号执行scrape_data()。