Skip to content

Commit 11d8355

Browse files
committed
Review
1 parent c1179ed commit 11d8355

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

docs/notes/dev-tools/google-colab/pip.ipynb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
"\n",
1717
"But it is very common to want to use other packages in the Python ecosystem as well, including any packages we might find shared on [GitHub](https://github.com/), or hosted more officially on the Python Package Index ([PyPI](https://pypi.org/)), which is a centralized repository for all official Python packages.\n",
1818
"\n",
19-
"To manage the Python package installation process, we use Python's sidekick, a command-line tool called [Pip](https://packaging.python.org/en/latest/tutorials/installing-packages/#use-pip-for-installing).\n",
20-
"\n",
21-
":::{.callout-note}\n",
22-
"In Google Colab, when we use terminal commands (such as `pip` commands), we prefix them with an exclamation point (!), to differentiate them from Python code.\n",
23-
":::\n"
19+
"To manage the Python package installation process, we use Python's sidekick, a command-line tool called [Pip](https://packaging.python.org/en/latest/tutorials/installing-packages/#use-pip-for-installing).\n"
2420
]
2521
},
2622
{
@@ -46,6 +42,16 @@
4642
"!pip --version"
4743
]
4844
},
45+
{
46+
"cell_type": "markdown",
47+
"metadata": {},
48+
"source": [
49+
"\n",
50+
":::{.callout-note}\n",
51+
"In Google Colab, when we use terminal commands (such as `pip` commands), we prefix them with an exclamation point (!), to differentiate them from Python code.\n",
52+
":::"
53+
]
54+
},
4955
{
5056
"cell_type": "code",
5157
"execution_count": null,

docs/notes/python-lang/file-operations.qmd

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@ We can use the `open` function in "writing" mode (`"w"`) to write text contents
2525
```{python}
2626
filepath = "my_message.txt"
2727
28-
# "w" means "open the file for writing":
2928
with open(filepath, "w") as file:
3029
file.write(message)
3130
```
3231

33-
Let's break this down. As the first parameter we first specify the name (or the full path) of the file we want to reference.
32+
Let's break this down.
3433

35-
Then as the second parameter specifies the "mode", or the way in which we intend to open the file (i.e. reading or writing).
34+
When using the `open` function, we pass the name (or the full path) of the file as the first parameter, then the "mode", or the way in which we intend to open the file (i.e. reading or writing), as the second parameter.
3635

36+
:::{.callout-note}
3737
FYI: the `with` statement creates a **context manager** that allows us to open the file without explicitly closing it. The file will be closed when the indentation level resets back to the left margin.
38+
:::
3839

39-
FYI: here, `file` is an alias variable referencing the file object (technically a `TextIOWrapper` datatype). You can choose any variable name you like instead, just reference that same variable name inside the scope of the context manager when reading with the file's `read` method, or writing with the file's `write` method.
40+
:::{.callout-note}
41+
Here, `file` is an alias variable referencing the file object (technically a `TextIOWrapper` datatype). You can choose any variable name you like instead, just reference that same variable name inside the scope of the context manager when reading with the file's `read` method, or writing with the file's `write` method.
42+
:::
4043

4144
## Reading Files
4245

@@ -45,15 +48,14 @@ To verify the contents got written to file, let's read the same file.
4548
Here we are use the `open` function in "reader" mode (`"r"`) to read the contents of the text file:
4649

4750
```{python}
48-
# "r" means "open the file for reading":
4951
with open(filepath, "r") as file:
5052
contents = file.read()
5153
print(contents)
5254
```
5355

5456
## Removing Files
5557

56-
We can use the `os` module to detect, and delete files:
58+
Finally, we can use the `os` module to detect, and delete files:
5759

5860
```{python}
5961
import os

0 commit comments

Comments
 (0)