[Python-ideas] Make Difflib example callable as module __main__

Terry Reedy tjreedy at udel.edu
Wed Feb 22 22:40:32 CET 2012


On 2/22/2012 10:49 AM, Dan Colish wrote:

> I was reading over the difflib docs this morning and when I got to the
> bottom, I expected, probably due to lack of coffee, that the example
> would be callable as the module from the command line.

This is slightly garbled, but after looking, I see what you mean.
As the doc says, the 'example' is available as Tools/Scripts/diff.
Tools/Scripts/ndiff is another command-line front end for difflib.
I believe difflib was extracted from the original version of ndiff.

 > There are already
> a number of modules which export command line functionality, ie.
> unittest, and I thought it would be great if difflib module offered the
> same.

If you run difflib directly, it runs difflib._test. which runs a doctest 
on difflib. Most modules do something similar. Having a real 
command-line interface in the module itself is unusual.

 > The code is pretty much there in the example from the
> documentation. It would just need to be included in the module itself.

I don't immediately see it as worth the trouble. I bet someone somewhere 
has a script that uses the interface in its current location.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list