The nature of how Python handles mutable and immutable data can make it easy to accidentally modify a different variable when passing mutable data structures into functions or methods as arguments. Being able to use a dictionary or list a variable’s contents without changing the original can be very handy for creating a default configuration, or as a data template. In this hands-on lab, you’ll be writing a small script that utilizes a data template to help generate information about a real estate transaction while ensuring that the original data isn’t modified during the process. Completing this lab will demonstrate that you understand how data copying works within Python.
Successfully complete this lab by achieving the following learning objectives:
- Parse the Template JSON File
There should always be a
template.jsonfile next to the script so that it can get an up-to-date picture of the values that don’t change. When the script is initially run, this should be parsed and stored as the
- Prompt for the Values That Need to Be Changed
When the tool is run, it should present the user with a series of prompts like this:
$ python real_estate.py Address Street 1: [prompt] Street 2: [prompt] City: [prompt] State: [prompt] ZIP: [prompt] Details Square Footage: [prompt] Bedrooms: [prompt] Bathrooms: [prompt] Ammenities (use | between items): [prompt] Was there a referrer? (Y or n): [prompt] Referrer: [prompt ONLY if Y to previous]
- Export New Data to a New JSON File
Write the dictionary with the new values to a JSON file named after the street address of the property with the spaces converted to dashes.