deleting the first and the last character of a string

Padraig Brady padraig.brady at corvil.com
Wed Sep 11 08:02:47 EDT 2002


Manuel Hendel wrote:
> On Wed, Sep 11, 2002 at 12:30:40PM +0100, Padraig Brady wrote:
> 
>>How about: line = line[1:-1]
> 
> 
> This worked quite good, but I found another problem. There seams to be
> trailing whitespaces. I tried to strip(s) to get rid of them, but this
> doesn't work, I get the following error message:
> 
> Traceback (most recent call last):
>   File "./pop3create.py", line 9, in ?
>       print strip(line)
>       NameError: name 'strip' is not defined
> 
> What's wrong here?
> 
> manuel
> 

You need to do: line.strip()
Note the alternative is to 'import string'
before you 'string.strip(line)' however
it's much better IMHO to use the new
string methods on the string object.

Pádraig.





More information about the Python-list mailing list