-
-
Save bmackenty/d02b8df6d51bbca06a1c694fd4975b1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def create_person(): | |
# Create a person | |
first_name = input("Enter first name: ") | |
last_name = input("Enter last name: ") | |
person = { | |
"id": 1, | |
"first_name": first_name, | |
"last_name": last_name, | |
"second_last_name": "Smith", | |
"date_of_birth": "1980-01-01", | |
"city": "New York", | |
"has_children": False, | |
"gender": "M", | |
"titles": ["engineer", "programmer"] | |
} | |
# Write to file | |
with open("person.json", "w") as f: | |
json.dump(person, f) | |
def read_person(): | |
# Read from file | |
with open("person.json", "r") as f: | |
person = json.load(f) | |
print(person) | |
def main(): | |
create_person() | |
read_person() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment