Dec-07-2016, 06:54 PM
JSON file that contains the following pieces of information:
import json
def setup(filename):
"""(str) -> dict
The function reads from the specified configuration file, in JSON format, and stores the contents
in a Python dictionary. That dictionary is returned to the caller, as shown in #4.
>>> setup('/final/config_sample.json').get("Database User")
'slucor'
>>> setup('/final/config_sample.json').get("Cost Field Mapping")["MG001"][0]
'ingredient_cost'
>>> setup('/final/config_sample.json').get("Cost Field Mapping").get("AZ001")[1]
'admin_fee'
"""
with open (filename, "r") as inputFile:
data=inputFile.read().replace('\n', '')
return json.loads(data)
print(setup('config_sample.json').get("Database User"))
print(setup('config_sample.json').get("Cost Field Mapping")["00400F"][0])
print(setup('config_sample.json').get("Cost Field Mapping").get("00670H")[1])
Please help me correc it . ITs not working
- Database Connection Information:
- Database User Name
- Database Password
- Database Host
- Database Name
- Database User Name
- Start Date - The start date for data to process, in the format YYYY-MM-DD
- End Date - The end date for data to process, in the format YYYY-MM-DD
- Cost Field Mapping - This is a dictionary that contains entries that describe which fields should be summed to compute an output field, total cost
import json
def setup(filename):
"""(str) -> dict
The function reads from the specified configuration file, in JSON format, and stores the contents
in a Python dictionary. That dictionary is returned to the caller, as shown in #4.
>>> setup('/final/config_sample.json').get("Database User")
'slucor'
>>> setup('/final/config_sample.json').get("Cost Field Mapping")["MG001"][0]
'ingredient_cost'
>>> setup('/final/config_sample.json').get("Cost Field Mapping").get("AZ001")[1]
'admin_fee'
"""
with open (filename, "r") as inputFile:
data=inputFile.read().replace('\n', '')
return json.loads(data)
print(setup('config_sample.json').get("Database User"))
print(setup('config_sample.json').get("Cost Field Mapping")["00400F"][0])
print(setup('config_sample.json').get("Cost Field Mapping").get("00670H")[1])
Please help me correc it . ITs not working