|
165 | 165 | "source": [ |
166 | 166 | "with open('tmp/date_file.txt', 'w') as file:\n", |
167 | 167 | " for i in range(10):\n", |
168 | | - " print(f'{i} ', end='', file=file)\n", |
| 168 | + " print(f'{i} ', end='', file=file, flush=True)\n", |
169 | 169 | " sh.date(_out=file)\n", |
170 | 170 | " sh.sleep('1')" |
171 | 171 | ] |
172 | 172 | }, |
| 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 | + }, |
173 | 180 | { |
174 | 181 | "cell_type": "code", |
175 | 182 | "execution_count": null, |
|
220 | 227 | { |
221 | 228 | "cell_type": "code", |
222 | 229 | "execution_count": null, |
223 | | - "metadata": {}, |
| 230 | + "metadata": { |
| 231 | + "scrolled": true |
| 232 | + }, |
224 | 233 | "outputs": [], |
225 | 234 | "source": [ |
226 | 235 | "sh.grep(sh.ls('-l'), r'\\.ipynb$')" |
|
241 | 250 | }, |
242 | 251 | "outputs": [], |
243 | 252 | "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')" |
254 | 254 | ] |
255 | 255 | }, |
256 | 256 | { |
|
512 | 512 | }, |
513 | 513 | "outputs": [], |
514 | 514 | "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", |
516 | 516 | "p2 = subprocess.Popen(['sort', '-r'], stdin=p1.stdout, stdout=subprocess.PIPE, encoding='utf8')\n", |
517 | 517 | "p1.stdout.close()\n", |
518 | 518 | "output, _ = p2.communicate()\n", |
|
0 commit comments