#NEWLINE# def _choice( prompt , valid_values = None , file_exists = False , optional = False ) : #NEWLINE# #INDENT# '\n    A method used to help prompt the user for input and validate user input. If\n    valid_values is provided _choice confirms the input is in valid_values and\n    returns the input. If file_exists is True _choice confirms the file exists\n    and returns the absolute path of the file. If optional is True then None\n    will be returned if the user does not provide any input.\n    ' #NEWLINE# choice = input ( prompt ) . strip ( ) #NEWLINE# if ( optional and ( choice == '' ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# if ( valid_values is not None ) : #NEWLINE# #INDENT# while ( choice not in valid_values ) : #NEWLINE# #INDENT# print ( ( choice + ' is not a valid option.' ) ) #NEWLINE# choice = input ( prompt ) . strip ( ) #NEWLINE# if ( optional and ( choice == '' ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if file_exists : #NEWLINE# #INDENT# while ( not os . path . isfile ( choice ) ) : #NEWLINE# #INDENT# print ( ( ( 'File ' + choice ) + ' does not exist.' ) ) #NEWLINE# choice = input ( prompt ) . strip ( ) #NEWLINE# if ( optional and ( choice == '' ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# return os . path . abspath ( choice ) #NEWLINE# #UNINDENT# #UNINDENT# return choice