运行以下代码后,您可以在' index'
中获取五个索引的列表import tkinter as tk
OPTIONS = [ "^AEX","^AXJO","^BFX","^BSESN","^MERV","^DJR","^PUT","^OMXC20","^DJA","^DJI","^DJICA","^DJT","^DJU","^DWCF"]
root = tk.Tk()
tk.Label(root, text='OptionMenus', bg='#aaa').pack(fill='x')
index = []
def on_button():
index.clear()
for i,var in enumerate(o_vars):
index.append('{}'.format(var.get()))
index.__str__()
print('Selected Index {}: {}'.format(i+1, var.get()))
print()
o_vars = []
for i in range(5):
var = tk.StringVar(value='- select -')
o_vars.append(var)
o = tk.OptionMenu(root, var, *OPTIONS)
o.pack()
b = tk.Button(root, text='OK', command=on_button)
b.pack(fill='x')
root.mainloop()
根据您的选择,它看起来像:
index
Out: ['^BSESN', '^DJI', '^HSI', '^JKII', '^KS11']
现在我必须将此字符串输入到下面代码末尾的另一行代码中,查找部分索引[0],索引[1] ...索引[4]
这没有发生。我的猜测是必须由于需要双引号。 任何关于如何实现它的想法。尝试替换和所有。
import pandas as pd
import urllib
import datetime
import requests
import pylab
x =[]
yql_bs_query = []
yql_bs_url = []
data=[]
quote_new =[]
baseurl = "https://query.yahooapis.com/v1/public/yql?"
from datetime import date
import numpy as np
start_date = date(2007, 1, 1)
end_date = datetime.date.today()
delta = datetime.timedelta(np.timedelta64(end_date - start_date,'D').astype(int) /20)
while start_date <= end_date:
x.append(start_date.strftime("%Y-%m-%d"))
start_date += delta
for i in range(0,20):
x[i] = str.format((pd.to_datetime(x[i]) + datetime.timedelta(days=1)).strftime("'%Y-%m-%d'"))
yql_bs_query.append(('select * from yahoo.finance.historicaldata where symbol in (index[0],index[1],index[2],index[3],index[4]) and startDate = ' +x[i]+' and endDate = ' +pd.to_datetime(x[i+1]).strftime("'%Y-%m-%d'") ))`
答案 0 :(得分:0)
'select * from yahoo.finance.historicaldata where symbol in (index[0],index[1],index[2],index[3],index[4]) and startDate = '
实际上没有替换索引值,因为它只是将其视为文字字符串,而是需要至少对它们应用一些字符串格式化。
'select * from yahoo.finance.historicaldata where symbol in ({}, {}, {}, {}, {}) and startDate = '.format(index[0],index[1],index[2],index[3],index[4])
哪个应该至少让你更接近正确的sql字符串。
尽管如此,您应该确保使用parameterized queries来避免bobby tables