Message356624
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 |
|
Date |
User |
Action |
Args |
2019-11-14 18:39:58 | tim.peters | set | recipients:
+ tim.peters, simon_ |
2019-11-14 18:39:58 | tim.peters | set | messageid: <1573756798.33.0.551373131214.issue38789@roundup.psfhosted.org> |
2019-11-14 18:39:58 | tim.peters | link | issue38789 messages |
2019-11-14 18:39:58 | tim.peters | create | |
|