Skip to content

Commit 3122215

Browse files
committed
Fix example
1 parent fb8ea04 commit 3122215

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

hands-on/shell_interaction.ipynb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,18 @@
165165
"source": [
166166
"with open('tmp/date_file.txt', 'w') as file:\n",
167167
" for i in range(10):\n",
168-
" print(f'{i} ', end='', file=file)\n",
168+
" print(f'{i} ', end='', file=file, flush=True)\n",
169169
" sh.date(_out=file)\n",
170170
" sh.sleep('1')"
171171
]
172172
},
173+
{
174+
"cell_type": "markdown",
175+
"metadata": {},
176+
"source": [
177+
"Note the use of the `flush` optional argument in the print function. If this is omitted, the Python interpreter will only flush the results of its own print calls after the `sh` modules has written its output."
178+
]
179+
},
173180
{
174181
"cell_type": "code",
175182
"execution_count": null,
@@ -220,7 +227,9 @@
220227
{
221228
"cell_type": "code",
222229
"execution_count": null,
223-
"metadata": {},
230+
"metadata": {
231+
"scrolled": true
232+
},
224233
"outputs": [],
225234
"source": [
226235
"sh.grep(sh.ls('-l'), r'\\.ipynb$')"
@@ -241,16 +250,7 @@
241250
},
242251
"outputs": [],
243252
"source": [
244-
"sh.sort(sh.cut('-d', ' ', '-f', '6', 'tmp/date_file.txt'), '-r')"
245-
]
246-
},
247-
{
248-
"cell_type": "code",
249-
"execution_count": null,
250-
"metadata": {},
251-
"outputs": [],
252-
"source": [
253-
"_ = sh.rm('-r', 'tmp')"
253+
"sh.sort(sh.cut('-d', ' ', '-f', '5', 'tmp/date_file.txt'), '-r')"
254254
]
255255
},
256256
{
@@ -512,7 +512,7 @@
512512
},
513513
"outputs": [],
514514
"source": [
515-
"p1 = subprocess.Popen(['cut', '-d', ' ', '-f', '6', 'tmp/data.txt'], stdout=subprocess.PIPE)\n",
515+
"p1 = subprocess.Popen(['cut', '-d', ' ', '-f', '5', 'tmp/data.txt'], stdout=subprocess.PIPE)\n",
516516
"p2 = subprocess.Popen(['sort', '-r'], stdin=p1.stdout, stdout=subprocess.PIPE, encoding='utf8')\n",
517517
"p1.stdout.close()\n",
518518
"output, _ = p2.communicate()\n",

0 commit comments

Comments
 (0)