string.split() documentation incorrect?

carroll at tjc.com carroll at tjc.com
Fri Apr 11 12:39:00 EDT 2003


On Fri, 11 Apr 2003 09:52:32 -0600, Jerry Seutter
<jerry.seutter at pason.com> wrote:

>I'm trying to use string.strip to remove the comma off the end of 
>a string, eg:
>
>string.strip("id INT NOT NULL,", ",")
>
>The current documentation says I can do this.  Python 2.2.2 gives
>the following error:
>
>>>> strip('  hello  ', ',')
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>TypeError: strip() takes exactly 1 argument (2 given)
>
>So, I think either the documentation is incorrect or there is 
>a bug.  Thoughts?

Yeah, it's a bug, bug number 697220.  See
http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=697220
there's a patch available.

However, use of the string module is deprecated in favor of methods of
the string class, which work as documented.  The string module only
calls the equivalent class method anyway, e.g., string.strip(s) turns
into s.strip().

Save yourself some trouble and use the class method directly, e.g.,
instead of these:

 >>> string.strip(s,",")
 >>> string.strip("id INT NOT NULL,",",")

use these:

 >>> s.strip(",")
 >>> "id INT NOT NULL,".strip(",")





More information about the Python-list mailing list