deleting the first and the last character of a string

Duncan Booth duncan at NOSPAMrcp.co.uk
Wed Sep 11 18:03:59 CEST 2002


Sean 'Shaleh' Perry <shalehperry at attbi.com> wrote in 
news:mailman.1031756234.22942.python-list at python.org:

> On Wednesday 11 September 2002 03:58, Manuel Hendel wrote:
>> I got a file with fields seperated by a "|". The problem is that there
>> is also a "|" at the beginning and at the end of each line although
>> there no fields in front or behind these "|". Now I want to delete
>> these two "|". Is there anything which says delete the first or last
>> character of a string? I checked the string module on the web, but I
>> couldn't find anything.
>>
> 
>>>> s = '|f|o|o|'
>>>> s.strip('|')
> 'f|o|o'
> 
> and of course the equivalent strip call from the string module.
> 
This doesn't work on Python 2.2.1 (or earlier), I think you need to be 
sitting astride the cutting edge of CVS development to do this.

Specifically the change to implement this was April 22nd and 2.2.1 was 
released April 10th.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list