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

Dan Colish dcolish at gmail.com
Wed Feb 22 22:47:59 CET 2012


On 2/22/12 1:40 PM, Terry Reedy wrote:
> 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.
>
Yes, I realized shortly after sending how unintelligible that sounded.
Yes, even thought those tools exist, they are not installed as part of
the Python build.
> > 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.
>
Oh, I was unaware of that behavior. That's really good to know. Is this
behavior documented?
> > 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.
>
I didn't think it would be that much trouble. It would be simple to
install the scripts from Tools/Scripts. Either way I liked the idea of
providing a cli frontend to difflib as part of the python install.

--Dan



More information about the Python-ideas mailing list