Skip to content

TASK: Add method to save a Person to a file #152

Description

@TheGittyPerson

Leave a comment if you want to work on this task!

*This task is an extension of task #142. You can wait for that one to be completed and merged first, or take/help complete the task.

Difficulty: Lower Intermediate to Intermediate

TODO:

  • Create a method called save_to_file() in the Person class in person.py. It's goal is to save a serialized copy of the Person instance as JSON data.
  • The method should have two paramters: a path parameter of type Path (from pathlib), and a create parameter of type bool which defaults to True.
    • The Path should have a .json extension. If it doesn't, append it to the file name.
    • If create is True, the file is created if it does not exist. An error is raised is create is False and the file does not exist yet.
  • Add a load_from_file classmethod to do the opposite (without the create parameter and returns a Person). If the assignee of task 142 did not make a from_json() method, you don't have to do this.
  • Remember to add type hints and docstrings where necessary and follow PEP 8

PR steps:

  1. Fork this repo
  2. Clone the forked repo
  3. Create a new branch and name it feature/person-save-to-file
  4. Push commits to your remote fork
  5. Create a pull request titled TASK: Add method to save a `Person` to a file (#152)
  6. At the end of the PR description, add Closes #152
  7. Submit the PR (Ensure you allow maintainers to edit)

Please make sure you have read the Contributing Guidelines before working.


Feel free to ask any questions here!

If you are interested in working on this task, please leave a comment requesting assignment to explicitly let others know the task is taken and prevent duplicate PRs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    continuationContinued or extended from a previous task/PR/issuefeatureNew feature or enhancementgood first issueGood for newcomershelp wantedExtra attention is neededtaskThis is a task issue / PR completing a task🐜 Lower IntermediateGood for growing devs with some confidence in programming🦟 IntermediateGood for growing devs who've been coding for a while

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions