[Tutor] Find files without __doc__ strings
Kent Johnson
kent37 at tds.net
Sun May 17 20:53:43 CEST 2009
On Sat, May 16, 2009 at 9:46 PM, David <david at abbottdavid.com> wrote:
> I am doing an exercise in Wesley Chun's book. Find files in the standard
> library modules that have doc strings. Then find the ones that don't, "the
> shame list". I came up with this to find the ones with;
> #!/usr/bin/python
> import os
> import glob
> import fileinput
> import re
>
> pypath = "/usr/lib/python2.6/"
> fnames = glob.glob(os.path.join(pypath, '*.py'))
>
> def read_doc():
> pattern = re.compile('"""*\w')
> for line in fileinput.input(fnames):
> if pattern.match(line):
> print 'Doc String Found: ', fileinput.filename(), line
>
> read_doc()
>
> There must have been an easier way :)
One problem with this is that not every triple-quoted string is a doc
string. Another problem is that doc strings can use
triple-single-quotes.
You might look at how pydoc (in the std lib) solves this problem.
Kent
More information about the Tutor
mailing list