My son wants me to teach him Python

Jason Swails jason.swails at gmail.com
Fri Jun 14 13:03:12 EDT 2013


On Fri, Jun 14, 2013 at 3:21 AM, Chris Angelico <rosuav at gmail.com> wrote:

> On Fri, Jun 14, 2013 at 4:13 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
> > Here's another Pepsi Challenge for you:
> >
> > There is a certain directory on your system containing 50 text files, and
> > 50 non-text files. You know the location of the directory. You want to
> > locate all the text files in this directory containing the word
> > "halibut", then replace the word "halibut" with "trout", but only if the
> > file name begins with a vowel.
>
> That sounds extremely contrived, to be honest.


I agree that it sounds contrived, but I've found analogous tasks to be
quite common in the program suite I work on, actually.

We have a set of regression tests for obvious reasons.  To give an order of
magnitude estimate here, there are over 1100 saved test files that get
compared when we run the test suite.

When a change is made to the information reporting (for instance, if we
added a new input variable) or version number that is printed in the output
files, we have ourselves ~2K files.  We then have to scan through all 2K
files (some of which are ASCII, others of which are binary), typically
armed with a regex that identifies the formatting change we just
implemented and change the saved test files (all file names that end in
.save) to the 'new' format. Our task is to find only those files that end
in .save and replace only those files that differ only by the trivial
formatting change to avoid masking a bug in the test suite. [I'm actually
doing this now]

On the whole, it sounds quite similar to Steven's example (only
significantly more files), and is something not even RR could do in a GUI
faster than I can run a script.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130614/19402744/attachment.html>


More information about the Python-list mailing list