After running following code, you can get list of five indexes in '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()
Based on your selection it looks like:
index
Out: ['^BSESN', '^DJI', '^HSI', '^JKII', '^KS11']
Now I have to input this string to another code of line at the end of following code, look for the part index[0],index[1]...index[4]
This is not happening. My guess is it must be due to required double quotation. Any idea on how to achieve it. Tried Replace and all.
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'") ))`