Skip to content

Commit 45f85b9

Browse files
committed
Fix various small things
* Leave directory clean by removing temporary directory * Change processes to list from chrome to python * Fix typos
1 parent d384805 commit 45f85b9

File tree

1 file changed

+69
-16
lines changed

1 file changed

+69
-16
lines changed

hands-on/shell_interaction.ipynb

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# Intereacting with the shell"
7+
"# Interacting with the shell"
88
]
99
},
1010
{
@@ -18,7 +18,7 @@
1818
"cell_type": "markdown",
1919
"metadata": {},
2020
"source": [
21-
"The [`sh` module](https://amoffat.github.io/sh/) is very convenient to interact with the shell. Note that `sh` is not part of Python's standard library, if you prefer not to use extra modules, use the `subprocess` module in the standard library."
21+
"The [`sh` module](https://amoffat.github.io/sh/) is very convenient to interact with the shell. Note that `sh` is not part of Python's standard library, if you prefer not to use extra modules, use the `subprocess` module in the standard library. The statements below will install `sh` using `pip` is it isn't already installed."
2222
]
2323
},
2424
{
@@ -27,16 +27,12 @@
2727
"metadata": {},
2828
"outputs": [],
2929
"source": [
30-
"!pip install sh"
31-
]
32-
},
33-
{
34-
"cell_type": "code",
35-
"execution_count": null,
36-
"metadata": {},
37-
"outputs": [],
38-
"source": [
39-
"import sh"
30+
"try:\n",
31+
" import sh\n",
32+
"except ModuleNotFoundError:\n",
33+
" print('installing sh using pip')\n",
34+
" !pip install sh\n",
35+
" import sh"
4036
]
4137
},
4238
{
@@ -314,7 +310,9 @@
314310
{
315311
"cell_type": "code",
316312
"execution_count": null,
317-
"metadata": {},
313+
"metadata": {
314+
"tags": []
315+
},
318316
"outputs": [],
319317
"source": [
320318
"try:\n",
@@ -323,6 +321,29 @@
323321
" print(error)"
324322
]
325323
},
324+
{
325+
"cell_type": "markdown",
326+
"metadata": {},
327+
"source": [
328+
"### Clean up"
329+
]
330+
},
331+
{
332+
"cell_type": "markdown",
333+
"metadata": {},
334+
"source": [
335+
"Remove the `tmp` directory."
336+
]
337+
},
338+
{
339+
"cell_type": "code",
340+
"execution_count": null,
341+
"metadata": {},
342+
"outputs": [],
343+
"source": [
344+
"sh.rm('-rf', 'tmp')"
345+
]
346+
},
326347
{
327348
"cell_type": "markdown",
328349
"metadata": {},
@@ -605,11 +626,43 @@
605626
" env=environ, shell=True)\n",
606627
"print(process.stdout.rstrip())"
607628
]
629+
},
630+
{
631+
"cell_type": "markdown",
632+
"metadata": {},
633+
"source": [
634+
"### Clean up"
635+
]
636+
},
637+
{
638+
"cell_type": "markdown",
639+
"metadata": {},
640+
"source": [
641+
"Remove the `tmp` directory."
642+
]
643+
},
644+
{
645+
"cell_type": "code",
646+
"execution_count": null,
647+
"metadata": {},
648+
"outputs": [],
649+
"source": [
650+
"process = subprocess.run(['rm', '-rf', 'tmp'])"
651+
]
652+
},
653+
{
654+
"cell_type": "code",
655+
"execution_count": null,
656+
"metadata": {},
657+
"outputs": [],
658+
"source": [
659+
"process.returncode"
660+
]
608661
}
609662
],
610663
"metadata": {
611664
"kernelspec": {
612-
"display_name": "Python 3",
665+
"display_name": "Python 3 (ipykernel)",
613666
"language": "python",
614667
"name": "python3"
615668
},
@@ -623,9 +676,9 @@
623676
"name": "python",
624677
"nbconvert_exporter": "python",
625678
"pygments_lexer": "ipython3",
626-
"version": "3.7.5"
679+
"version": "3.11.3"
627680
}
628681
},
629682
"nbformat": 4,
630-
"nbformat_minor": 2
683+
"nbformat_minor": 4
631684
}

0 commit comments

Comments
 (0)