list - How do I create an error message using pickAFile() in Jython? -
i creating program various calculations list of numbers.
how can show error message if presses "cancel" while choosing file pickafile()
? when cancel it, error message for line in file
line.
the error message is:
>"the error was:stream closed > i/o operation failed. > > tried read file, , couldn't. sure file exists? > if exist, did specify correct directory/folder?"
here's code:
def selectfilecalculatestatistics(): fullpathname = pickafile() file = open(fullpathname, "r") listnumbers = readlistnumbers(file) min = calculateminimum(listnumbers) max = calculatemaximum(listnumbers) mean = calculatemean(listnumbers) standarddeviation = calculatestandarddeviation(listnumbers, mean) print("the minimum number list is: " + str(min)) print("the maximum number list is: \n" + str(max)) print("the mean number list is: " + str(round(mean, 2))) print("the standard deviation list is: " + str(round(standarddeviation, 2))) file.close() def readlistnumbers(fullpathname): file = open(fullpathname, "r") listnumbers = [] line in file: listnumbers.append(float(line.rstrip('\n'))) return listnumbers
while pickafile()
returns none
if user pressed cancel button can raise exception:
fullpathname = pickafile() if not fullpathname: raise ioerror('cancel pressed')
Comments
Post a Comment