<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 23, 2015 at 8:20 AM, Burton, Ross <span dir="ltr"><<a href="mailto:ross.burton@intel.com" target="_blank">ross.burton@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_extra"><span><div class="gmail_quote">On 23 October 2015 at 11:38, Peter Kjellerstedt <span dir="ltr"><<a href="mailto:peter.kjellerstedt@axis.com" target="_blank">peter.kjellerstedt@axis.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="overflow:hidden">- field = line.rstrip().split(":")<br>
+ # Make sure there always are at least seven elements in<br>
+ # the field list. This allows for leaving out trailing<br>
+ # colons in the passwd file.<br>
+ line = line.rstrip() + "::::::"<br>
+ field = line.split(":")</div></blockquote></div><br></span>It's a stylist thing but I prefer padding the field list instead of manipulating the input string. Something like</div><div class="gmail_extra"><br></div><div class="gmail_extra"> field = line.strip().split(":")</div><div class="gmail_extra"> field += [''] * (7 - len(field))</div></blockquote></div><br clear="all"><div>Agreed, but I think this is cleaner:</div><div><br></div><div><div>def iter_extend(iterable, length, obj=None):</div><div> """Ensure that iterable is the specified length by extending with obj"""</div><div> return itertools.islice(itertools.chain(iterable, itertools.repeat(obj)), length)</div></div><div><br></div><div>fields = iter_extend(line.rstrip().split(":"), 7)</div>-- <br><div>Christopher Larson<br>clarson at kergoth dot com<br>Founder - BitBake, OpenEmbedded, OpenZaurus<br>Maintainer - Tslib<br>Senior Software Engineer, Mentor Graphics</div>
</div></div>