Skip to content

Instantly share code, notes, and snippets.

@bmackenty
Last active September 18, 2022 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmackenty/d02b8df6d51bbca06a1c694fd4975b1d to your computer and use it in GitHub Desktop.
Save bmackenty/d02b8df6d51bbca06a1c694fd4975b1d to your computer and use it in GitHub Desktop.
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