This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients simon_, tim.peters
Date 2019-11-14.18:39:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1573756798.33.0.551373131214.issue38789@roundup.psfhosted.org>
In-reply-to
Content
Please be explicit:  exactly which functions are you talking about, and exactly what do you want them to do instead.  Since, best I can tell, this is the first complaint of its kind, it's a pretty safe bet people can't guess what you want ;-)

Note that, e.g., Differ(...).compare(...) returns a generator-iterator.  There is no general way in Python to know whether a generator will yield a non-empty sequence of results without running the generator.  This is common to all generators, not unique to those difflib returns.

So, of course, the same kinds of idioms can be used as for any other generator.  For example:

foundone = False
for line in difflib.Differ(...).compare(...):
    if not foundone:
        # there is at least one result, and this is the first
        # maybe print a header line here, or whatever
        foundone = True
    process(line)
if not foundone:
    # the generator produced nothing

Simpler to code is to force the results into a list instead, but then you lose the possible memory-saving advantages of iterating over a generator:

    result = list(difflib.Differ(...).compare(...))
    if result:
        # there are results to deal with
    else:
        # the generator produced nothing
History
Date User Action Args
2019-11-14 18:39:58tim.peterssetrecipients: + tim.peters, simon_
2019-11-14 18:39:58tim.peterssetmessageid: <1573756798.33.0.551373131214.issue38789@roundup.psfhosted.org>
2019-11-14 18:39:58tim.peterslinkissue38789 messages
2019-11-14 18:39:58tim.peterscreate