Difficulty with maxsplit default value for str.split

Fredrik Lundh fredrik at pythonware.com
Sun Sep 24 10:34:31 CEST 2006

Steven D'Aprano wrote:

> I'm having problems passing a default value to the maxsplit argument of
> str.split. I'm trying to write a function which acts as a wrapper to
> split, something like this:
> def mysplit(S, sep=None, maxsplit=None):
>     pre_processing()
>     result = S.split(sep, maxsplit)
>     post_processing()
>     return result
> But the split method doesn't accept a value of None for maxsplit, and I
> don't know what default value I should be using.

     def mysplit(S, *args):
	result = S.split(*args)
	return result

> Is it safe for me to pass -1 as the default to maxsplit, meaning
> "unlimited splits"?

not really.


More information about the Python-list mailing list