Difficulty with maxsplit default value for str.split
Fredrik Lundh
fredrik at pythonware.com
Sun Sep 24 04:34:31 EDT 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):
pre_processing()
result = S.split(*args)
post_processing()
return result
> Is it safe for me to pass -1 as the default to maxsplit, meaning
> "unlimited splits"?
not really.
</F>
More information about the Python-list
mailing list