Unicode and Python - how often do you index strings?

Ryan Hiebert ryan at ryanhiebert.com
Thu Jun 5 16:05:45 EDT 2014


On Thu, Jun 5, 2014 at 2:59 PM, Chris Angelico <rosuav at gmail.com> wrote:

> On Fri, Jun 6, 2014 at 4:52 AM, Ryan Hiebert <ryan at ryanhiebert.com> wrote:
> > 2014-06-05 13:42 GMT-05:00 Johannes Bauer <dfnsonfsduifb at gmx.de>:
> >
> >> On 05.06.2014 20:16, Paul Rubin wrote:
> >> > Johannes Bauer <dfnsonfsduifb at gmx.de> writes:
> >> >> line = line[:-1]
> >> >> Which truncates the trailing "\n" of a textfile line.
> >> >
> >> > use line.rstrip() for that.
> >>
> >> rstrip has different functionality than what I'm doing.
> >
> >
> > How so? I was using line=line[:-1] for removing the trailing newline, and
> > just replaced it with rstrip('\n'). What are you doing differently?
>
> >>> line = "Hello,\nworld!\n\n"
> >>> line[:-1]
> 'Hello,\nworld!\n'
> >>> line.rstrip('\n')
> 'Hello,\nworld!'
>
> If it's guaranteed to end with exactly one newline, then and only then
> will they be identical.
>
>  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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140605/6781b8d1/attachment.html>


More information about the Python-list mailing list