Jan-24-2017, 03:26 PM
This asks for a file path and returns the size of only avi files in the folder. I need to do further math with these numbers, which is where I am stuck. Things in """ section and # areas are things I've rotated in to try but all give errors about not being able to interate through floats.
from Tkinter import * import os import math root = Tk() root.title("DVD Calculator") spinbox1 = Spinbox(root, values= ("SD", "HD"), wrap = TRUE) spinbox1.grid(row=0, column=1, padx=105, pady=15) lbl1 = Label(root, text="File Path", width=8) lbl1.grid(row=2, column=2, pady=15, sticky=W) entry1 = Entry(root, justify= RIGHT, width=55) entry1.grid(row=2, column=1, pady=15) def reset(): entry1.delete(0, END) global file_path global total def file_size(): """ this function will return the file size """ file_path = entry1.get() filepaths = [] #gets list of avi for basename in os.listdir(file_path): filename = os.path.join(file_path, basename) if not filename.endswith(('.mov', '.AVI', '.avi')): continue if os.path.isfile(filename): filepaths.append(filename) # Re-populate list with size, convert to GB for i in xrange(len(filepaths)): filepaths[i] = (os.path.getsize(filepaths[i])) nums = filepaths[i] i = int(math.floor(math.log(nums, 1024))) p = math.pow(1024, i) s = round(nums/p, 2) total = s # fred = [float(x) for x in total] # fred = list(map(float, total)) print s fred = ', '.join(s) fred = map(float, fred) print fred ''' #change list for can iterate thru floats newlist = [] for i in total: tok = i.split(total) for num in total: newlist.append(float(tok[num])) total.append(newlist) print newlist first = s[0:] * .20 print first if type(i)== float: newlist.append(i) print newlist def frange(total, end=None, inc=None): "A range function, that does accept float increments..." if end == None: end = total + 0.0 start = 0.0 if inc == None: inc = 1.0 L = [] while 1: next = total + len(L) * inc if inc > 0 and next >= end: break elif inc < 0 and next <= end: break L.append(next) print frange(total) ''' resetButton = Button(root, text="Reset", command= reset) resetButton.grid(row=4, column=1, pady=100) calcButton = Button(root, text="Calculate", command=file_size) calcButton.grid(row=4, column=2) root.geometry("450x350+200+100") root.mainloop()