{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Files, Paths, Projects, and Reproducibility\n",
        "\n**Opening question:** How can a project find its data tomorrow, on another computer, and after being uploaded to a website?\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "from pathlib import Path\n",
        "\n",
        "root = Path.cwd()\n",
        "figure_path = root / \"figures\" / \"example.png\"\n",
        "print(figure_path.suffix)\n",
        "print(figure_path.parent.name)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. The path expresses the file type and project role without assuming an operating system.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import json\n",
        "from pathlib import Path\n",
        "\n",
        "metadata = {\n",
        "    \"provider\": \"Bank of Canada\",\n",
        "    \"series\": \"FXUSDCAD\",\n",
        "    \"retrieved\": \"2026-08-15\",\n",
        "}\n",
        "path = Path(\"data/metadata/example.json\")\n",
        "path.parent.mkdir(parents=True, exist_ok=True)\n",
        "path.write_text(json.dumps(metadata, indent=2), encoding=\"utf-8\")\n",
        "print(path.exists())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Interpretation check:** Interpretation. Metadata becomes a first-class project artifact rather than a memory held by one analyst.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "from pathlib import Path\n",
        "root = Path.cwd()\n",
        "print(figure_path.suffix)\n",
        "print(figure_path.parent.name)\n",
        "import json\n",
        "from pathlib import Path\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Verified source output\n",
        "\n",
        "```text\n.png figures\n```\n\n```text\nTrue\n```\n\n```text\n.png\nfigures\n```\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3"
    },
    "ceteris_lab": {
      "course_slug": "fundamentals-python-econometrics",
      "source_derived": true,
      "course_title": "Fundamentals of Python for Financial Econometrics",
      "chapter": 7,
      "source_origin": "source-derived"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
