|
12 | 12 | }, |
13 | 13 | { |
14 | 14 | "cell_type": "code", |
15 | | - "execution_count": 7, |
16 | 15 | "id": "f7f8b7ff-2950-4c93-b874-2f99d53bb669", |
17 | 16 | "metadata": { |
18 | 17 | "ExecuteTime": { |
19 | | - "end_time": "2025-07-23T16:35:41.612096Z", |
20 | | - "start_time": "2025-07-23T16:35:41.608392Z" |
| 18 | + "end_time": "2025-08-02T01:13:40.632240Z", |
| 19 | + "start_time": "2025-08-02T01:13:40.628063Z" |
21 | 20 | } |
22 | 21 | }, |
23 | | - "outputs": [], |
24 | 22 | "source": [ |
25 | 23 | "# Import our math utility functions.\n", |
26 | 24 | "import mathf\n", |
27 | 25 | "from pathlib import Path" |
28 | | - ] |
| 26 | + ], |
| 27 | + "outputs": [], |
| 28 | + "execution_count": 2 |
29 | 29 | }, |
30 | 30 | { |
31 | 31 | "cell_type": "markdown", |
|
111 | 111 | }, |
112 | 112 | { |
113 | 113 | "cell_type": "code", |
114 | | - "execution_count": 19, |
115 | 114 | "id": "5deaf5a6", |
116 | | - "metadata": {}, |
117 | | - "outputs": [ |
118 | | - { |
119 | | - "name": "stdout", |
120 | | - "output_type": "stream", |
121 | | - "text": [ |
122 | | - "This is run 10\n" |
123 | | - ] |
| 115 | + "metadata": { |
| 116 | + "ExecuteTime": { |
| 117 | + "end_time": "2025-08-02T01:14:53.816909Z", |
| 118 | + "start_time": "2025-08-02T01:14:53.792645Z" |
124 | 119 | } |
125 | | - ], |
| 120 | + }, |
126 | 121 | "source": [ |
127 | 122 | "# Let's just show that we can read/write data persistently.\n", |
128 | 123 | "file = Path('/data/run-count.txt')\n", |
129 | 124 | "if not file.parent.exists():\n", |
130 | 125 | " file = Path('../data/run-count.txt')\n", |
| 126 | + " file.parent.mkdir(parents=True, exist_ok=True)\n", |
131 | 127 | "\n", |
132 | 128 | "if file.exists():\n", |
133 | 129 | " with open(file, 'r', encoding='utf-8') as f:\n", |
|
141 | 137 | " f.write(str(run_count))\n", |
142 | 138 | "\n", |
143 | 139 | "print(f'This is run {run_count}')" |
144 | | - ] |
| 140 | + ], |
| 141 | + "outputs": [ |
| 142 | + { |
| 143 | + "ename": "IsADirectoryError", |
| 144 | + "evalue": "[Errno 21] Is a directory: '../data/run-count.txt'", |
| 145 | + "output_type": "error", |
| 146 | + "traceback": [ |
| 147 | + "\u001B[31m---------------------------------------------------------------------------\u001B[39m", |
| 148 | + "\u001B[31mIsADirectoryError\u001B[39m Traceback (most recent call last)", |
| 149 | + "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[6]\u001B[39m\u001B[32m, line 8\u001B[39m\n\u001B[32m 5\u001B[39m file.parent.mkdir(parents=\u001B[38;5;28;01mTrue\u001B[39;00m, exist_ok=\u001B[38;5;28;01mTrue\u001B[39;00m)\n\u001B[32m 7\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m file.exists():\n\u001B[32m----> \u001B[39m\u001B[32m8\u001B[39m \u001B[38;5;28;01mwith\u001B[39;00m \u001B[38;5;28;43mopen\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mfile\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[33;43m'\u001B[39;49m\u001B[33;43mr\u001B[39;49m\u001B[33;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mencoding\u001B[49m\u001B[43m=\u001B[49m\u001B[33;43m'\u001B[39;49m\u001B[33;43mutf-8\u001B[39;49m\u001B[33;43m'\u001B[39;49m\u001B[43m)\u001B[49m \u001B[38;5;28;01mas\u001B[39;00m f:\n\u001B[32m 9\u001B[39m run_count = \u001B[38;5;28mint\u001B[39m(f.read())\n\u001B[32m 10\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n", |
| 150 | + "\u001B[36mFile \u001B[39m\u001B[32m~/github/courses/just-enough-python-datasci/just-enough-data-sci-course/venv/lib/python3.13/site-packages/IPython/core/interactiveshell.py:343\u001B[39m, in \u001B[36m_modified_open\u001B[39m\u001B[34m(file, *args, **kwargs)\u001B[39m\n\u001B[32m 336\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m file \u001B[38;5;129;01min\u001B[39;00m {\u001B[32m0\u001B[39m, \u001B[32m1\u001B[39m, \u001B[32m2\u001B[39m}:\n\u001B[32m 337\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[32m 338\u001B[39m \u001B[33mf\u001B[39m\u001B[33m\"\u001B[39m\u001B[33mIPython won\u001B[39m\u001B[33m'\u001B[39m\u001B[33mt let you open fd=\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mfile\u001B[38;5;132;01m}\u001B[39;00m\u001B[33m by default \u001B[39m\u001B[33m\"\u001B[39m\n\u001B[32m 339\u001B[39m \u001B[33m\"\u001B[39m\u001B[33mas it is likely to crash IPython. If you know what you are doing, \u001B[39m\u001B[33m\"\u001B[39m\n\u001B[32m 340\u001B[39m \u001B[33m\"\u001B[39m\u001B[33myou can use builtins\u001B[39m\u001B[33m'\u001B[39m\u001B[33m open.\u001B[39m\u001B[33m\"\u001B[39m\n\u001B[32m 341\u001B[39m )\n\u001B[32m--> \u001B[39m\u001B[32m343\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mio_open\u001B[49m\u001B[43m(\u001B[49m\u001B[43mfile\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43m*\u001B[49m\u001B[43margs\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43m*\u001B[49m\u001B[43m*\u001B[49m\u001B[43mkwargs\u001B[49m\u001B[43m)\u001B[49m\n", |
| 151 | + "\u001B[31mIsADirectoryError\u001B[39m: [Errno 21] Is a directory: '../data/run-count.txt'" |
| 152 | + ] |
| 153 | + } |
| 154 | + ], |
| 155 | + "execution_count": 6 |
| 156 | + }, |
| 157 | + { |
| 158 | + "metadata": {}, |
| 159 | + "cell_type": "code", |
| 160 | + "outputs": [], |
| 161 | + "execution_count": null, |
| 162 | + "source": "", |
| 163 | + "id": "2e12bad509461386" |
145 | 164 | } |
146 | 165 | ], |
147 | 166 | "metadata": { |
|
0 commit comments