am i missing something ?
aleax at aleax.it
Sat Apr 12 17:00:29 CEST 2003
> i would like to strip only non white space from a string, i have found
> strip in documentation as :
> Return a copy of the string with leading and trailing characters removed.
> If chars is omitted or None, whitespace characters are removed. If given
> and not None, chars must be a string; the characters in the string will be
> stripped from the both ends of the string this method is called on.
This is true in Python 2.2.2 (the current stable version), 2.3 (the
current alpha ones), and future ones. It was not true in 2.2.1 and
> but i can't get it work :
>>>> s = 'this is an example \n'
> Traceback (most recent call last):
> File "<pyshell#184>", line 1, in ?
> TypeError: strip() takes no arguments (1 given)
> i think i'm missing something...
Yes -- you missed telling us what version of Python you use. E.g.,
[alex at lancelot Modules]$ python2.2
Python 2.2.2 (#1, Oct 24 2002, 11:43:01)
[GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = 'this is an example \n'
'this is an example '
but older versions would give the behavior you report. Of course,
the docs refer to a specific version, too -- the online ones are
normally appropriate for the latest stable version (well, there are
several online ones, but as you don't tell us where you took your
docs reference, it's hard to guess...).
More information about the Python-list