3 messages in org.python.python-bugs-list[ python-Bugs-911080 ] string str.spl...
FromSent OnAttachments
SourceForge.netMar 6, 2004 3:41 pm 
SourceForge.netMar 7, 2004 2:23 am 
SourceForge.netMar 7, 2004 5:59 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[ python-Bugs-911080 ] string str.split() behaviour inconsistencyActions...
From:SourceForge.net (nore@sourceforge.net)
Date:Mar 7, 2004 5:59:50 am
List:org.python.python-bugs-list

Bugs item #911080, was opened at 2004-03-06 21:41 Message generated for change (Comment added) made by sjoerd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=911080&group_id=5470

Category: Python Interpreter Core

Group: Not a Bug Status: Closed

Resolution: None Priority: 5 Submitted By: Pete Shinners (peteshinners) Assigned to: Raymond Hettinger (rhettinger) Summary: string str.split() behaviour inconsistency

Initial Comment: The str.split() method behaves differently depending on if it uses the default (no arguments) separator, or if you provide your own. There is no way to reproduce the functionality of the default separator if you supply your own.

s = "a b c" s.split() ['a', 'b', 'c'] s.split(" ")

['a', 'b', '', 'c']

The default split uses a different algorithm, where it combines multiple separators into a single separator. Providing a custom separator makes split separate each individual separator.

Obviously there are good reasons for forcing a separate entry between each separator. With simple comma or colon separated records, you want to know if an entry is blank.

The problem is there is not a way to reproduce the functionality of the default behavior. This alternate behavior is also not documented, so it becomes confusing why split behaves different once you want your own separators.

Fixing could be a problem. Changing the actual split() method would break many programs. But adding an different split is a potentially nice solution.

The other option would be to "re-use" the current splitfields() function and have it work like the current split. And change the split() to behave like it does with no default. This would unfortunately still "break stuff".

The easiest fix may just be documentation and letting people know of this difference.

I've been helping some newbies through Python. When this came up I was a little surprised and we were forced to learn it was just a little "magic and scary".

----------------------------------------------------------------------

Comment By: Sjoerd Mullender (sjoerd)

Date: 2004-03-07 12:00

Message: Logged In: YES user_id=43607

Use s.split(None) to get the same behavior as without arguments. This is documented behavior, as far as I know. If the documentation isn't good enough, submit a bug report specifically for that.

----------------------------------------------------------------------