Permalink
Browse files

Added example runs in docstring comment.

  • Loading branch information...
nvie committed May 19, 2010
1 parent f61f38d commit 634eb3abfe1b825713f2051936dffb9e63668dea
Showing with 20 additions and 6 deletions.
  1. +12 −4 examples/simple_annotate_date.py
  2. +8 −2 examples/simple_find.py
@@ -1,15 +1,23 @@
"""
-Simply call "ls -a", no special stuff.
+Annotate each line coming in with the current date.
+
+Example runs:
+python simple_annotate_date.py find .
+python simple_annotate_date.py cat (and start typing in stdin)
+python simple_annotate_date.py grep 'foobar' *
"""
import sys
import datetime
import drainers
def annotate(line, is_err):
- sys.stdout.write('[%s] ' % datetime.datetime.now())
if is_err:
- sys.stdout.write('ERROR: ')
- sys.stdout.write(line)
+ stream = sys.stderr
+ else:
+ stream = sys.stdout
+ stream.write('[%s] ' % datetime.datetime.now())
+ stream.write('ERROR: ')
+ stream.write(line)
d = drainers.Drainer(sys.argv[1:], read_event_cb=annotate)
d.start()
View
@@ -1,6 +1,12 @@
"""
-Simple finder. Search for a file called "foobar" for a maximum of 10
-seconds, then abort. Present results of found files and errors.
+Simple finder. Search for the file given in sys.argv[1] for a maximum of
+10 seconds, then abort. Present results of found files and errors.
+
+For the best demonstration effect, make the find run long (for example,
+run the script from /).
+
+Example runs:
+python simple_find.py <somefile>
"""
import sys
import drainers

0 comments on commit 634eb3a

Please sign in to comment.