[Tutor] strip function

Kent Johnson kent37 at tds.net
Wed Dec 24 14:09:12 CET 2008


On Wed, Dec 24, 2008 at 7:25 AM, Norman Khine <norman at khine.net> wrote:
>
> Hello,
> I have difficulties in trying to stripping the following:
>
>>>> item_path = '/companies/company/news'
>>>> item_strip = item_path.strip('/companies')
>>>> item_strip
> 'y/new'

strip() doesn't do what you want. It removes any of the characters in
the given string, in any order.

> I would like to return:
>
>>>> item_strip
> '/company/news'
>
> What is the best way to do this.

To remove a fixed string use slicing:
item_strip = item_path[len('/companies'):]

Kent


More information about the Tutor mailing list