diff python/walk.py @ 810:0afeb265da7f

fix formatting bug
author Jeff Hammel <k0scist@gmail.com>
date Fri, 28 Oct 2016 17:33:35 -0700
parents b3f75f1361c5
children
line wrap: on
line diff
--- a/python/walk.py	Fri Oct 28 17:27:32 2016 -0700
+++ b/python/walk.py	Fri Oct 28 17:33:35 2016 -0700
@@ -4,10 +4,17 @@
 illustration of walking a directory structure
 """
 
+# imports
 import argparse
 import os
 import sys
 
+
+def ensure_dir(path):
+    """ensures `path` is a directory"""
+    return os.path.isdir(path)
+
+
 def all_files(directory):
     filenames = []
     for dirpath, dirnames, files in os.walk('/home/jhammel/music'):
@@ -18,8 +25,14 @@
 def main(args=sys.argv[1:]):
     """CLI"""
 
+
+    # parse command line
+
+    # sanity
     if not args:
         print "Usage: %s directory [directory] [...]" % os.path.basename(sys.argv[0])
+
+    # process command line
     for arg in args:
         if os.path.isdir(arg):
             for i in all_files(arg):
@@ -27,7 +40,8 @@
         elif os.path.isfile(arg):
             print os.path.abspath(arg)
         else:
-            print >> sys.stderr, "'%s' not a file or directory"
+            sys.stderr.write("'%s' not a file or directory\n" % arg)
+
 
 if __name__ == '__main__':
     main()