Poppy:
> var = "detail.xml"
> print var.strip(".xml")   ### expect to see 'detail', but get 'detai'
> var = "overview.xml"
> print var.strip(".xml") ### expect and get 'overview'

Python V.2.5 is not flawless, but you can't find bugs so easily. I've
found only two bugs in about three years of continuous usage (while I
have found about 27 new different bugs in the DMD compiler in about
one year of usage).

str.strip() isn't a module, and generally in Python it's called
"method", in this case a method of str (or unicode).

str.strip() as optional argument doesn't take the string you want to
remove, but a string that represent the set of chars you want to strip
away from both ends, so:

>>> "detail.xml".strip("lmx.")
'detai'
>>> "detail.xml".strip("abcdlz")
'etail.xm'

To strip the ending ".xml" you can use the str.partition() method, or
an alternative solution:

>>> var = "detail.xml"
>>> suffix = ".xml"
>>> if var.endswith(suffix):
...     var2 = var[: -len(suffix)]
...
>>> var2
'detail'

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to