Question: I need help fixing my code and finishing it. I'm trying to use the Try and accept and else. It's missing the some of the

I need help fixing my code and finishing it. I'm trying to use the Try and accept and else. It's missing the some of the file configuration. The files basic_config.json and config_override was alredy created, no need to create it.

I upload the file

(this part is already done)First, to start by writing a JSON file called ("basic_config.json") that stores the following variables and their associated values:

1. Safe Mode - "On" 2. Memory - "32MB" 3. Error Log - "logs/errors.log"

Your program is going to load all of these values up on startup, display them just like I have them above, and then give the user the option to either modify an existing value or add new ones.

(need help over)Use your program to add the following configuration options below in the code given the user the option to add it or not (note that you are not limited to just these - add them using your program):

Allow File Uploads - "Yes" Use Caching - "Yes" Caching File - "cache/filecache.cache" Mail Host - "mail.apphost.com"

(need help here) give the user the option to either save their changes or discard them. If the user chooses to accept the changes, the new configuration will be saved as config_override.json. Under no circumstances should basic_config.json ever be overwritten.

On subsequent program runs, in order to make this work properly, you are going to need to implement a check to see if config_override.json exists before loading the information in basic_config.json. In other words, once basic_config.json has been overridden, you should always load config_override.json from that point on to make your changes and adjustments. When you save back, you must have a means in place to backup your old file. You do not need to have functionality in place to have your applications load or restore data from old backups.

Users may modify the value of any setting they wish, but they can only delete configurations not in the original configuration such as:

Allow File Uploads - "Yes" Use Caching - "Yes" Caching File - "cache/filecache.cache" Mail Host - "mail.apphost.com"

In other words, the keys contained in the basic_config.json file are all required. You must add logic and decide the best way to delete items the user wishes to remove.

Finally, you will create functions to (minimally - you can and probably should write more functions than the ones listed below) handle the following tasks:

  • Loading the information from the proper configuration file
  • Saving configuration data.
  • Adding a configuration

I need help fixing my code and finishing it. I'm trying to

use the Try and accept and else. It's missing the some of

1 2 #create a code that check if config_override.json file exists #if it does, load the data in it #if doesn't, load the data in basic_config.json instead 3 4 Nm 00 5 6 #print the data you are working with out 7 #ask the user what the they would like to do 8 9 #All the file exist 10 11 #add the follow configuration options: Allow File Uploads, Use Caching, Caching File, Mail Host, File backup, 12 13 14 import json 15 16 with open("text_files/basic config.json", "r") as file: conf = json.load(file) 17 = 18 19 print(conf) 20 21 22 23 = 24 def edit_basic_config(conf, keys): ***"Edit the basic configuration and return new modified dict""" ans = input("Do you want to change existing parametrs? y :") if ans =="y": conf["Safe Mode" ] = input("Safe Mode: ") conf["Memory"] = input("Memory: ") conf["Error log"] = input("Error Log: ") 25 = 26 = 27 28 29 30 31 32 = ans = input("Do you want to enter new configuration parameter? y :") if ans=="y": while(True): key input("Enter configuration parameter: ") conf[key] = input(key + ":")) want_to_add = input("Do you want add more? y :") if want_to_add "n": break 33 34 35 = == 36 37 38 39 40 41 42 43 44 ans = input("Do you want to delete any parameter? y ") if ans == "y": while(True): k = input("Enter key: ") if k not in keys: del conf[k] else: print("Cannot delete", k) remove = input("Do you want to remove more parameter? y :") if remove =="n": break return conf 45 46 47 48 49 50 51 52 def override(): 53 54 55 56 57 58 59 60 61 62 63 try: with open("text_files/config_override.json") as file_object: try: configuration = json.load(file_object, conf) except: return None except FileNotFoundError: return None else: return configuration 64 65 66 67

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!