I’m new here, but look here often for help. Anyways, I am trying to use tkSimpleDialog.askinteger() to ask for how many files the user needs to read into the program. I want to read the files in based on the integer that the user inputs in a for loop. I would index the file names f[1] through f[n] for the file names. Any input would be greatly appreciated!
Please view below for an idea of what I am trying to get at:
def callback2():
NumDates = tkSimpleDialog.askinteger("NDates", "How many dates are there?")
for dates in NumDates:
filename[dates] = tkFileDialog.askopenfilename()
dates = dates + 1
filenameDates.append(filename)
Assuming
NumDatesis an integer, you’re looking for the range function:In python 2.x, you can use
xrangeinstead. This doesn’t create an intermediate list so many people prefer it. In python 3,xrangewas renamedrangeand the former range function which returns a list was removed — When the lists are small, I usually just userangefor compatibility, but there exist tools (2to3) to take care of these details for you as well, so it really isn’t a big deal either way.aside
Also, as written, there really is no need for the
dates = dates + 1(which is better written asdates += 1when necessary).