Skip to content
Myr

Updated inout example

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 38eb59c · Browse files · 1 file+24 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+24 added−7 removed

  • other:+24 added−7 removed

1 file+24 added−7 removed

modified:examples/inout/inout.py+24 added-7 removed
1import click234@click.command()5@click.argument('input', type=click.File('rb'))5@click.argument('input', type=click.File('rb'), nargs=-1)6@click.argument('output', type=click.File('wb'))7def cli(input, output):8 """This script works similar to the unix `cat` command but it writes9 into a specific file (which could be the standard output as denoted by10 the ``-`` sign).1112 \b13 Copy stdin to stdout:14 inout - -1516 \b17 Copy foo.txt and bar.txt to stdout:18 inout foo.txt bar.txt -1920 \b21 Write stdin into the file foo.txt22 intout - foo.txt23 """24 for f in input:8 while True:9 chunk = input.read(1024)10 if not chunk:11 break12 output.write(chunk)13 output.flush()25 while True:26 chunk = f.read(1024)27 if not chunk:28 break29 output.write(chunk)30 output.flush()