<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jun 5, 2014 at 2:59 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Fri, Jun 6, 2014 at 4:52 AM, Ryan Hiebert <<a href="mailto:ryan@ryanhiebert.com">ryan@ryanhiebert.com</a>> wrote:<br>

> 2014-06-05 13:42 GMT-05:00 Johannes Bauer <<a href="mailto:dfnsonfsduifb@gmx.de">dfnsonfsduifb@gmx.de</a>>:<br>
><br>
>> On 05.06.2014 20:16, Paul Rubin wrote:<br>
>> > Johannes Bauer <<a href="mailto:dfnsonfsduifb@gmx.de">dfnsonfsduifb@gmx.de</a>> writes:<br>
>> >> line = line[:-1]<br>
>> >> Which truncates the trailing "\n" of a textfile line.<br>
>> ><br>
>> > use line.rstrip() for that.<br>
>><br>
>> rstrip has different functionality than what I'm doing.<br>
><br>
><br>
> How so? I was using line=line[:-1] for removing the trailing newline, and<br>
> just replaced it with rstrip('\n'). What are you doing differently?<br>
<br>
</div></div>>>> line = "Hello,\nworld!\n\n"<br>
>>> line[:-1]<br>
'Hello,\nworld!\n'<br>
>>> line.rstrip('\n')<br>
'Hello,\nworld!'<br>
<br>
If it's guaranteed to end with exactly one newline, then and only then<br>
will they be identical.<br><span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div> OK, that's not an issue for my case, and additionally I'm using the open(_, 'U') file iterable, so I shouldn't see multiple trailing newlines anyway.</div>
</div><br></div></div>