On Sat, May 16, 2009 at 9:46 PM, David <da...@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 _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor