|
21 | 21 | "source": [
|
22 | 22 | "You have learned about lists as well as how to write your own functions with loops and conditional statements. As such, you can already write programs performing a variety of tasks. \n",
|
23 | 23 | "\n",
|
24 |
| - "However, something that is currently missing is a mechanism to access the data that you want to analyze. A very common way to access these data is through (local or remotely-stored) [files](https://en.wikipedia.org/wiki/Computer_file)." |
| 24 | + "However, something that you are currently missing is a mechanism to access the data that you want to analyze. A very common way to access these data is through (local or remotely-stored) [files](https://en.wikipedia.org/wiki/Computer_file)." |
25 | 25 | ]
|
26 | 26 | },
|
27 | 27 | {
|
|
78 | 78 | "cell_type": "markdown",
|
79 | 79 | "metadata": {},
|
80 | 80 | "source": [
|
81 |
| - "We will first introduce some file managing capability of the `os` [Python module](https://docs.python.org/3.6/tutorial/modules.html#modules), then we will describe the use of the functions that Python natively provides for [reading and writing the content of a text file](https://docs.python.org/3.6/tutorial/inputoutput.html)." |
| 81 | + "We will first introduce some file managing capability of the `os` [Python module](https://docs.python.org/3.6/tutorial/modules.html#modules), then we will describe the use of the functions that Python provides for [reading and writing the content of a text file](https://docs.python.org/3.6/tutorial/inputoutput.html)." |
82 | 82 | ]
|
83 | 83 | },
|
84 | 84 | {
|
|
127 | 127 | },
|
128 | 128 | {
|
129 | 129 | "cell_type": "code",
|
130 |
| - "execution_count": 1, |
131 |
| - "metadata": {}, |
132 |
| - "outputs": [ |
133 |
| - { |
134 |
| - "name": "stdout", |
135 |
| - "output_type": "stream", |
136 |
| - "text": [ |
137 |
| - "The current folder is: C:\\code\\hyo2\\epom\\python_basics\n" |
138 |
| - ] |
139 |
| - } |
140 |
| - ], |
| 130 | + "execution_count": null, |
| 131 | + "metadata": {}, |
| 132 | + "outputs": [], |
141 | 133 | "source": [
|
142 | 134 | "import os\n",
|
143 | 135 | "\n",
|
|
176 | 168 | },
|
177 | 169 | {
|
178 | 170 | "cell_type": "code",
|
179 |
| - "execution_count": 2, |
180 |
| - "metadata": {}, |
181 |
| - "outputs": [ |
182 |
| - { |
183 |
| - "name": "stdout", |
184 |
| - "output_type": "stream", |
185 |
| - "text": [ |
186 |
| - "The data folder is: C:\\code\\hyo2\\epom\\python_basics\\data\n" |
187 |
| - ] |
188 |
| - } |
189 |
| - ], |
| 171 | + "execution_count": null, |
| 172 | + "metadata": {}, |
| 173 | + "outputs": [], |
190 | 174 | "source": [
|
191 | 175 | "def get_data_folder():\n",
|
192 | 176 | " cur_folder = os.path.abspath(os.path.curdir)\n",
|
|
226 | 210 | },
|
227 | 211 | {
|
228 | 212 | "cell_type": "code",
|
229 |
| - "execution_count": 3, |
230 |
| - "metadata": {}, |
231 |
| - "outputs": [ |
232 |
| - { |
233 |
| - "name": "stdout", |
234 |
| - "output_type": "stream", |
235 |
| - "text": [ |
236 |
| - "The data paths are: ['C:\\\\code\\\\hyo2\\\\epom\\\\python_basics\\\\data\\\\ctd.txt', 'C:\\\\code\\\\hyo2\\\\epom\\\\python_basics\\\\data\\\\sal.txt', 'C:\\\\code\\\\hyo2\\\\epom\\\\python_basics\\\\data\\\\temp.txt']\n" |
237 |
| - ] |
238 |
| - } |
239 |
| - ], |
| 213 | + "execution_count": null, |
| 214 | + "metadata": {}, |
| 215 | + "outputs": [], |
240 | 216 | "source": [
|
241 | 217 | "def get_data_paths():\n",
|
242 | 218 | " data_paths = list() # create a empty list that will be populate and returned\n",
|
|
289 | 265 | },
|
290 | 266 | {
|
291 | 267 | "cell_type": "code",
|
292 |
| - "execution_count": 4, |
293 |
| - "metadata": {}, |
294 |
| - "outputs": [ |
295 |
| - { |
296 |
| - "name": "stdout", |
297 |
| - "output_type": "stream", |
298 |
| - "text": [ |
299 |
| - "The file path with index 1 is: C:\\code\\hyo2\\epom\\python_basics\\data\\sal.txt\n" |
300 |
| - ] |
301 |
| - } |
302 |
| - ], |
| 268 | + "execution_count": null, |
| 269 | + "metadata": {}, |
| 270 | + "outputs": [], |
303 | 271 | "source": [
|
304 | 272 | "sal_path = retrieved_paths[1]\n",
|
305 | 273 | "print(\"The file path with index 1 is: \" + sal_path)"
|
|
379 | 347 | },
|
380 | 348 | {
|
381 | 349 | "cell_type": "code",
|
382 |
| - "execution_count": 5, |
383 |
| - "metadata": {}, |
384 |
| - "outputs": [ |
385 |
| - { |
386 |
| - "name": "stdout", |
387 |
| - "output_type": "stream", |
388 |
| - "text": [ |
389 |
| - "31.4\n", |
390 |
| - "31.6\n", |
391 |
| - "30.5\n", |
392 |
| - "30.8\n", |
393 |
| - "30.4\n", |
394 |
| - "31.4\n", |
395 |
| - "31.6\n", |
396 |
| - "30.5\n", |
397 |
| - "30.3\n", |
398 |
| - "30.2\n", |
399 |
| - "31.4\n", |
400 |
| - "31.6\n", |
401 |
| - "32.5\n", |
402 |
| - "30.8\n", |
403 |
| - "31.4\n", |
404 |
| - "31.7\n", |
405 |
| - "31.6\n", |
406 |
| - "31.5\n", |
407 |
| - "30.2\n", |
408 |
| - "30.4\n", |
409 |
| - "\n" |
410 |
| - ] |
411 |
| - } |
412 |
| - ], |
| 350 | + "execution_count": null, |
| 351 | + "metadata": {}, |
| 352 | + "outputs": [], |
413 | 353 | "source": [
|
414 | 354 | "sal_file = open(sal_path)\n",
|
415 | 355 | "\n",
|
|
568 | 508 | },
|
569 | 509 | {
|
570 | 510 | "cell_type": "code",
|
571 |
| - "execution_count": 6, |
572 |
| - "metadata": {}, |
573 |
| - "outputs": [ |
574 |
| - { |
575 |
| - "name": "stdout", |
576 |
| - "output_type": "stream", |
577 |
| - "text": [ |
578 |
| - "The output folder is: C:\\code\\hyo2\\epom\\python_basics\\output\n" |
579 |
| - ] |
580 |
| - } |
581 |
| - ], |
| 511 | + "execution_count": null, |
| 512 | + "metadata": {}, |
| 513 | + "outputs": [], |
582 | 514 | "source": [
|
583 | 515 | "def get_output_folder():\n",
|
584 | 516 | " cur_folder = os.path.abspath(os.path.curdir)\n",
|
|
618 | 550 | },
|
619 | 551 | {
|
620 | 552 | "cell_type": "code",
|
621 |
| - "execution_count": 7, |
| 553 | + "execution_count": null, |
622 | 554 | "metadata": {},
|
623 | 555 | "outputs": [],
|
624 | 556 | "source": [
|
|
0 commit comments