[Python-3000] More wishful thinking
Terry Reedy
tjreedy at udel.edu
Mon Apr 17 02:02:34 CEST 2006
"Talin" <talin at acm.org> wrote in message
news:loom.20060416T073739-283 at post.gmane.org...
> Unfortunately, if the paragraph only contains a single word,
> this blows up. So what you end up having to do is:
>
> parts = paragraph.split( ' ', 1 )
> if len( parts ) > 1:
> first, rest = parts
> else:
> first = parts[ 0 ]
> rest = ""
>
> My objection here is that the intent of the code is cluttered
> up by the error-handling logic.
So wrap it all up in a function, especially if you need the logic more than
once.
> If I could do an argument-style unpack, however, I could instead
> write:
>
> first, *rest = paragraph.split( ' ', 1 )
first, rest = my_para_split(s,1)
tjr
More information about the Python-3000
mailing list