Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions notebooks/part0_python_intro/04_files_and_strings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
"\n",
"Files on non-volatile storage media are organized by a set of rules known as a **file system**. File systems are made up of files and **directories**, which are containers for both files and other directories.\n",
"\n",
"By default, when we create a new file by opening it goes in the current directory (wherever we were when we ran the program). Similarly, when we open a file for reading, Python looks for it in the current directory. In the above example, we have used `os.path.join()` to write the file to a specific directory rather than the directory we are running this notebook from. If `'test.txt'` was used in the `open` statement, the file would have been written to the current working directory. The current working directory can be determined using:"
"By default, when we create a new file by opening it goes in the current directory (wherever we were when we ran the program). Similarly, when we open a file for reading, Python looks for it in the current directory. In the above example, we have used `pathlib.Path` to write the file to a specific directory rather than the directory we are running this notebook from. If `'test.txt'` was used in the `open` statement, the file would have been written to the current working directory. The current working directory can be determined using:"
]
},
{
Expand All @@ -255,9 +255,7 @@
"metadata": {},
"outputs": [],
"source": [
"# The os module used to be the preferred way to access\n",
"# the current working directory; now we use pathlib\n",
"# os.getcwd()\n",
"# the pathlib Path object can be used to find the current working directory\n",
"\n",
"cwd = Path.cwd()\n",
"print(cwd)"
Expand All @@ -268,7 +266,7 @@
"id": "3a60f550",
"metadata": {},
"source": [
"Determine the directory that we wrote `'test.txt'` (`fname`) to in the blank code block below using `os.path.abspath()`:"
"Determine the directory that we wrote `'test.txt'` (`fname`) to in the blank code block below using `<Path>.resolve()` where `Path` indicates the `pathlib.Path` object:"
]
},
{
Expand All @@ -278,7 +276,6 @@
"metadata": {},
"outputs": [],
"source": [
"# os.path.abspath(fname)\n",
"print(fname)\n",
"\n",
"# to get the absolute path using pathlib, we use .resolve()\n",
Expand All @@ -296,7 +293,9 @@
"\n",
"`os.path` includes a number of useful methods for manipulating pathnames. For example, `os.path.normpath(path)` can be used to take Unix style paths into paths that can be used with Windows.\n",
"\n",
"Take a look at https://docs.python.org/3.9/library/os.path.html for more information of `os.path` methods."
"Take a look at https://docs.python.org/3.9/library/os.path.html for more information on `os.path` methods or https://docs.python.org/3/library/pathlib.html for more information on `pathlib.Path`.\n",
"\n",
"Alternatively, `pathlib.Path` stores and operates on paths in a operating-system-agnostic way."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
"\n",
"Files on non-volatile storage media are organized by a set of rules known as a **file system**. File systems are made up of files and **directories**, which are containers for both files and other directories.\n",
"\n",
"By default, when we create a new file by opening it goes in the current directory (wherever we were when we ran the program). Similarly, when we open a file for reading, Python looks for it in the current directory. In the above example, we have used `os.path.join()` to write the file to a specific directory rather than the directory we are running this notebook from. If `'test.txt'` was used in the `open` statement, the file would have been written to the current working directory. The current working directory can be determined using:"
"By default, when we create a new file by opening it goes in the current directory (wherever we were when we ran the program). Similarly, when we open a file for reading, Python looks for it in the current directory. In the above example, we have used `pathlib.Path` to write the file to a specific directory rather than the directory we are running this notebook from. If `'test.txt'` was used in the `open` statement, the file would have been written to the current working directory. The current working directory can be determined using:"
]
},
{
Expand All @@ -357,9 +357,7 @@
}
],
"source": [
"# The os module used to be the preferred way to access\n",
"# the current working directory; now we use pathlib\n",
"# os.getcwd()\n",
"# the pathlib Path object can be used to find the current working directory\n",
"\n",
"cwd = Path.cwd()\n",
"print(cwd)"
Expand All @@ -370,7 +368,7 @@
"id": "3a60f550",
"metadata": {},
"source": [
"Determine the directory that we wrote `'test.txt'` (`fname`) to in the blank code block below using `os.path.abspath()`:"
"Determine the directory that we wrote `'test.txt'` (`fname`) to in the blank code block below using `<Path>.resolve()` where `Path` indicates the `pathlib.Path` object:"
]
},
{
Expand All @@ -389,7 +387,6 @@
}
],
"source": [
"# os.path.abspath(fname)\n",
"print(fname)\n",
"\n",
"# to get the absolute path using pathlib, we use .resolve()\n",
Expand All @@ -407,7 +404,9 @@
"\n",
"`os.path` includes a number of useful methods for manipulating pathnames. For example, `os.path.normpath(path)` can be used to take Unix style paths into paths that can be used with Windows.\n",
"\n",
"Take a look at https://docs.python.org/3.9/library/os.path.html for more information of `os.path` methods."
"Take a look at https://docs.python.org/3.9/library/os.path.html for more information on `os.path` methods or https://docs.python.org/3/library/pathlib.html for more information on `pathlib.Path`.\n",
"\n",
"Alternatively, `pathlib.Path` stores and operates on paths in a operating-system-agnostic way."
]
},
{
Expand Down
Loading