|
19 | 19 | "cell_type": "markdown",
|
20 | 20 | "metadata": {},
|
21 | 21 | "source": [
|
22 |
| - "You have learned about lists and how to write your own functions with loops and conditional statements. This allows you to write programs performing a variety of tasks. \n", |
| 22 | + "You have learned about lists and how to [write your own functions](005_Write_Your_Own_Functions.ipynb) with [loops](004_Loops.ipynb) and [conditional statements](003_Conditional_Execution.ipynb). This allows you to write programs performing a variety of tasks. \n", |
23 | 23 | "\n",
|
24 | 24 | "However, a convenient mechanism to access data that you want to analyze is currently missing. In this notebook, we will explore the use of [files](https://en.wikipedia.org/wiki/Computer_file) since they are a common way to access stored data."
|
25 | 25 | ]
|
|
78 | 78 | "source": [
|
79 | 79 | "<img align=\"left\" width=\"6%\" style=\"padding-right:10px;\" src=\"images/key.png\">\n",
|
80 | 80 | "\n",
|
81 |
| - "In Python, a **module** is a file containing definitions and statements. " |
| 81 | + "In Python, a **module** is a file containing code (e.g., definitions and statements). " |
82 | 82 | ]
|
83 | 83 | },
|
84 | 84 | {
|
|
183 | 183 | "cell_type": "markdown",
|
184 | 184 | "metadata": {},
|
185 | 185 | "source": [
|
186 |
| - "To be able to access the `data` sub-folder, we extend the previous code using `os.path.join()` and `os.path.exist()` functions to:\n", |
| 186 | + "To be able to access the `data` sub-folder, we extend the previous code using `os.path.join()` and `os.path.exists()` functions to:\n", |
187 | 187 | "\n",
|
188 | 188 | "- Create the absolute path to the `data` sub-folder.\n",
|
189 | 189 | "- Check whether the resulting path actually exists."
|
|
242 | 242 | "cell_type": "markdown",
|
243 | 243 | "metadata": {},
|
244 | 244 | "source": [
|
245 |
| - "We will now retrieve all the paths to the files in the `data` folder. Specifically, we will create a function `get_data_paths()` that returns a list containing all the files in that folder, using the `os.listdir()` function." |
| 245 | + "We will now retrieve all the paths to the files in the `data` folder. Specifically, we will create a function `get_data_paths()` that returns a list containing all the files in that folder, using the `os.listdir()` function from the `os` module." |
246 | 246 | ]
|
247 | 247 | },
|
248 | 248 | {
|
|
251 | 251 | "metadata": {},
|
252 | 252 | "outputs": [],
|
253 | 253 | "source": [
|
| 254 | + "import os\n", |
| 255 | + "\n", |
254 | 256 | "def get_data_paths():\n",
|
255 | 257 | " data_paths = list() # create an empty list to be populated and returned\n",
|
256 | 258 | " data_folder = get_data_folder() # call the function you created to return the data directory path\n",
|
|
289 | 291 | "source": [
|
290 | 292 | "<img align=\"left\" width=\"6%\" style=\"padding-right:10px;\" src=\"images/key.png\">\n",
|
291 | 293 | "\n",
|
292 |
| - "You do not need to remember all the names of the available Python functions, but you need to learn how to search for them. The [official Python documentation](https://docs.python.org/3.6/index.html) is a good place to start. You can also get a list of the functions in the `os.path` module by entering `dir('os.path')` in a code cell." |
| 294 | + "You do not need to remember all the names of the available Python functions, but you need to learn how to search for them. The [official Python documentation](https://docs.python.org/3.6/index.html) is a good place to start. You can also get a list of the functions in the `os.path` module by entering `dir(os.path)` in a code cell." |
293 | 295 | ]
|
294 | 296 | },
|
295 | 297 | {
|
|
428 | 430 | "cell_type": "markdown",
|
429 | 431 | "metadata": {},
|
430 | 432 | "source": [
|
431 |
| - "You may ask why there are 100 characters instead of 80? Each of the 20 rows has 4 visible characters (e.g., `30.8`), but there is also the invisible [newline character](https://en.wikipedia.org/wiki/Newline) (i.e., `\\n`) that text editors treat as a new line. Thus, `(4+1) * 20 = 100` characters." |
| 433 | + "You may ask why there are 100 characters instead of 80? Each of the 20 rows has 4 visible characters (e.g., `30.8`), but there is also the invisible [newline character](https://en.wikipedia.org/wiki/Newline) (i.e., `\\n`) that text editors treat as a break between two lines. Thus, `(4+1) * 20 = 100` characters." |
432 | 434 | ]
|
433 | 435 | },
|
434 | 436 | {
|
|
0 commit comments