Message from discussion
Problem loading a file of words
Path: g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.powergate.ca!news.powergate.ca.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 25 Jul 2005 10:03:47 -0500
Date: Mon, 25 Jul 2005 11:03:45 -0400
From: Peter Hansen <pe...@engcorp.com>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: comp.lang.python
Subject: Re: Problem loading a file of words
References: <1122263048.404393.155960@z14g2000cwz.googlegroups.com> <1122298053.790180.292810@g43g2000cwa.googlegroups.com> <dc2qvb$ivn$01$1@news.t-online.com> <1122302368.508836.215150@f14g2000cwb.googlegroups.com>
In-Reply-To: <1122302368.508836.215150@f14g2000cwb.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <pIydnZzXIM3OYnnfRVn-3A@powergate.ca>
Lines: 19
NNTP-Posting-Host: 66.38.136.15
X-Trace: sv3-XRN01xh8uvgRIWvRPGSezNQ7iFfNs1wetNncPUwXiPKkhsgTS7yantYqCvw9zZLwG1/qV8divqAlowV!dBMYKm158+lmYlEMYzV7B3tVDrWmNLvrkNpuE1c6zNv/EYKjc50LAM2V1cXPyofAaZGiWKSwcGiU
X-Complaints-To: abuse@powergate.ca
X-DMCA-Complaints-To: ab...@powergate.ca
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.32
teoryn wrote:
> I changed to using line = line.strip() instead of line = line [:-1] in
> the original and it it worked.
Just to be clear, these don't do nearly the same thing in general,
though in your specific case they might appear similar.
The line[:-1] idiom says 'return a string which is a copy of the
original but with the last character, if any, removed, regardless of
what character it is'.
The line.strip() idiom says 'return a string with all whitespace
characters removed from the end *and* start of the string'.
In certain cases, you might reasonably prefer .rstrip() (which removes
only from the right-hand side, or end), or even something like
.rstrip('\n') which would remove only newlines from the end.
-Peter