Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Better way to write this?

$
0
0
I don't know if there is an easier way to write this in python

#SEARCH BY NAME
            if user_choice == '1' and action == '1':
                print_files((search_by_name(all_list)))

            elif user_choice == '1' and action == '2':
                print_first_line_of_text((search_by_name(all_list)))

            elif user_choice == '1' and action == '3':
                copy_file((search_by_name(all_list)))

            elif user_choice == '1' and action == '4':
                touch_file((search_by_name(all_list)))

            ###############

            #SEARCH BY NAME ENDING
            elif user_choice == '2' and action == '1':
                print_files((search_by_name_ending(all_list)))

            elif user_choice == '2' and action == '2':
                print_first_line_of_text((search_by_name_ending(all_list)))

            elif user_choice == '2' and action == '3':
                copy_file((search_by_name_ending(all_list)))

            elif user_choice == '2' and action == '4':
                touch_file((search_by_name_ending(all_list)))

            #################

            #SEARCH BY SIZE
            elif user_choice == '3' and action == '1':
                print_files((search_by_size(all_list)))

            elif user_choice == '3' and action == '2':
                print_first_line_of_text((search_by_size(all_list)))

            elif user_choice == '3' and action == '3':
                copy_file((search_by_size(all_list)))

            elif user_choice == '3' and action == '4':
                touch_file((search_by_size(all_list)))

         ############                           



there are 2 menus thats the user can choose from, user_choice and action

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>