Commits

Doug Hellmann committed 018476b

continue cog-ification

Comments (0)

Files changed (9)

PyMOTW/getpass/index.rst

+.. Not using cog because these examples are interactive.
+
 ==========================================================
 getpass -- Prompt the user for a password without echoing.
 ==========================================================

PyMOTW/glob/glob_asterisk.py

 #end_pymotw_header
 
 import glob
-print glob.glob('dir/*')
+for name in glob.glob('dir/*'):
+    print name

PyMOTW/glob/glob_charrange.py

 #end_pymotw_header
 
 import glob
-print glob.glob('dir/*[0-9].*')
+for name in glob.glob('dir/*[0-9].*'):
+    print name

PyMOTW/glob/glob_extension.py

 
 import glob
 
-filenames = glob.glob('*.py')
-print filenames
+for name in glob.glob('*.py'):
+    print name

PyMOTW/glob/glob_maketestdata.py

 import os
 
 def mkfile(filename):
+    print filename
     f = open(filename, 'wt')
     try:
         f.write('\n')
     finally:
         f.close()
 
+print 'dir'
 os.mkdir('dir')
+
 mkfile('dir/file.txt')
 mkfile('dir/file1.txt')
 mkfile('dir/file2.txt')
 mkfile('dir/filea.txt')
 mkfile('dir/fileb.txt')
+
+print 'dir/subdir'
 os.mkdir('dir/subdir')
+
 mkfile('dir/subdir/subfile.txt')

PyMOTW/glob/glob_question.py

 
 import glob
 
-print glob.glob('dir/file?.txt')
+for name in glob.glob('dir/file?.txt'):
+    print name

PyMOTW/glob/glob_subdir.py

 import glob
 
 print 'Named explicitly:'
-print glob.glob('dir/subdir/*')
+for name in glob.glob('dir/subdir/*'):
+    print '\t', name
 
 print 'Named with wildcard:'
-print glob.glob('dir/*/*')
+for name in glob.glob('dir/*/*'):
+    print '\t', name

PyMOTW/glob/index.rst

-===========
-glob
-===========
+=================================
+glob -- Filename pattern matching
+=================================
+
 .. module:: glob
     :synopsis: Use Unix shell rules to fine filenames matching a pattern.
 
-:Module: glob
 :Purpose: Use Unix shell rules to fine filenames matching a pattern.
 :Python Version: 1.4
 
-Description
-===========
-
 Even though the glob API is very simple, the module packs a lot of power. It
 is useful in any situation where your program needs to look for a list of
 files on the filesystem with names matching a pattern. If you need a list of
 The examples below assume the following test files are present in the current
 working directory:
 
+.. {{{cog
+.. from paver.path import path
+.. outdir = path(cog.inFile).dirname() / 'dir'
+.. outdir.rmtree()
+.. cog.out(run_script(cog.inFile, 'glob_maketestdata.py'))
+.. }}}
+
 ::
 
-    dir/
-    dir/file.txt
-    dir/file1.txt
-    dir/file2.txt
-    dir/filea.txt
-    dir/fileb.txt
-    dir/subdir/
-    dir/subdir/subfile.txt
+	$ python glob_maketestdata.py
+	dir
+	dir/file.txt
+	dir/file1.txt
+	dir/file2.txt
+	dir/filea.txt
+	dir/fileb.txt
+	dir/subdir
+	dir/subdir/subfile.txt
+
+.. {{{end}}}
 
 Use the glob_maketestdata.py script in the sample code to create these files
 if you want to run the examples.
 The pattern matches every pathname (file or directory) in the directory dir,
 without recursing further into subdirectories.
 
+.. {{{cog
+.. cog.out(run_script(cog.inFile, 'glob_asterisk.py'))
+.. }}}
+
 ::
 
-    $ python glob_asterisk.py
-    ['dir/file.txt', 'dir/file1.txt', 'dir/file2.txt',
-    'dir/filea.txt', 'dir/fileb.txt', 'dir/subdir']
+	$ python glob_asterisk.py
+	dir/file.txt
+	dir/file1.txt
+	dir/file2.txt
+	dir/filea.txt
+	dir/fileb.txt
+	dir/subdir
+
+.. {{{end}}}
 
 To list files in a subdirectory, you must include the subdirectory in the
 pattern:
 The first case above lists the subdirectory name explicitly, while the second
 case depends on a wildcard to find the directory.
 
+.. {{{cog
+.. cog.out(run_script(cog.inFile, 'glob_subdir.py'))
+.. }}}
+
 ::
 
-    $ python glob_subdir.py
-    Named explicitly:
-    ['dir/subdir/subfile.txt']
-    Named with wildcard:
-    ['dir/subdir/subfile.txt']
+	$ python glob_subdir.py
+	Named explicitly:
+		dir/subdir/subfile.txt
+	Named with wildcard:
+		dir/subdir/subfile.txt
+
+.. {{{end}}}
 
 The results, in this case, are the same. If there was another subdirectory,
 the wildcard would match both subdirectories and include the filenames from
 Matches all of the filenames which begin with "file", have one more character
 of any type, then end with ".txt".
 
+.. {{{cog
+.. cog.out(run_script(cog.inFile, 'glob_question.py'))
+.. }}}
+
 ::
 
-    $ python glob_question.py
-    ['dir/file1.txt', 'dir/file2.txt',
-    'dir/filea.txt', 'dir/fileb.txt']
+	$ python glob_question.py
+	dir/file1.txt
+	dir/file2.txt
+	dir/filea.txt
+	dir/fileb.txt
+
+.. {{{end}}}
 
 
 Character Ranges
 unbroken range of sequential characters. The same range value could be written
 [0123456789], in this case.
 
+.. {{{cog
+.. cog.out(run_script(cog.inFile, 'glob_charrange.py'))
+.. }}}
+
 ::
 
-    $ python glob_charrange.py
-    ['dir/file1.txt', 'dir/file2.txt']
+	$ python glob_charrange.py
+	dir/file1.txt
+	dir/file2.txt
+
+.. {{{end}}}
 
 
 .. seealso::
 
     `Pattern Matching Notation <http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html#tag_02_13>`_
         An explanation of globbing from The Open Group's Shell Command Language specification.
+
+    :mod:`fnmatch`
+        Filename matching implementation.

PyMOTW/history.rst

 History
 =======
 
+1.85
+  - Continue converting older articles to use cog.
+
 1.84
   - 22 Feb 2009, :mod:`tarfile`
   - Updated DictWriter example in :mod:`csv` based on feedback from Trilok Khairnar.