pretty strange behavior of "strip"

James Mills prologic at shortcircuit.net.au
Fri Dec 5 00:51:50 CET 2008


On Fri, Dec 5, 2008 at 9:35 AM, Guy Doune <cesium5500 at yahoo.ca> wrote:
>>>> test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html',
>>>> '01.html', '05.html', '07.html', '02.html', '08.html']
>>>> test
> ['03.html', '06.html', 'questions.html', '04.html', 'toc.html', '01.html',
> '05.html', '07.html', '02.html', '08.html']
>>>> test[4]
> 'toc.html'
>>>> test[4].strip('.html')
> 'oc'

I believe you're after this:

>>> test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html', '01.html', '05.html', '07.html', '02.html', '08.html']
>>> test
['03.html', '06.html', 'questions.html', '04.html', 'toc.html',
'01.html', '05.html', '07.html', '02.html', '08.html']
>>> from os.path import splitext
>>> files = [splitext(x)[0] for x in test]
>>> files
['03', '06', 'questions', '04', 'toc', '01', '05', '07', '02', '08']
>>>

And no, it's not a bug. Read the
docs :)

cheers
James

-- 
--
-- "Problems are solved by method"



More information about the Python-list mailing list