<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sat, Jun 9, 2018 at 6:28 AM Michel Desmoulin <<a href="mailto:desmoulinmichel@gmail.com">desmoulinmichel@gmail.com</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Example, open this files, load all lines in memory, skip the first line,<br>
then get all the line until the first comment:<br>
<br>
    import itertools<br>
<br>
    def is_commented(line):<br>
        return lines.startwith('#')<br>
<br>
    def lines():<br>
        with open('/etc/fstab'):<br>
            lines = f.readlines()[1:]<br>
            return list(itertools.dropwhile(lines, is_commented)<br>
<br>
Becomes:<br>
<br>
    def is_commented(line):<br>
        return lines.startwith('#')<br>
<br>
    def lines():<br>
        with open('/etc/fstab'):<br>
            return f.readlines()[1:is_commented]<br>
<br>
It's not about how much shorter is is, but it is very nice to read.<br></blockquote><div><br></div><div>If you're going to put it in a function anyway, why something like this?</div><div><br></div><div><div>    def lines():</div><div>        with open('/etc/fstab'):</div><div>            f.readline()</div><div>            for line in f:</div><div>                if line.startswith('#'):</div><div>                    break</div><div>                yield line</div></div></div></div>