[issue28937] str.split(): remove empty strings when sep is not None

2019-03-19 Thread Emanuel Barry
Emanuel Barry added the comment: Unfortunately not. I no longer have the time or means to work on this, sorry. I hope someone else can pick it up. -- ___ Python tracker ___

[issue28937] str.split(): remove empty strings when sep is not None

2019-03-19 Thread Emanuel Barry
Change by Emanuel Barry : -- nosy: -ebarry ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue28937] str.split(): remove empty strings when sep is not None

2019-03-19 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: @veky - Thank you for pointing out splitlines(keepends=True). If we wanted consistency, then we'd change the sense and use something like .split(keepempty=True), however: * I don't like run-on names, so I would suggest keep_empty * Maybe just `keep` is

[issue28937] str.split(): remove empty strings when sep is not None

2019-03-19 Thread Cheryl Sabella
Cheryl Sabella added the comment: @ebarry, any interest in converting your patch to a GitHub pull request? Thanks! -- nosy: +cheryl.sabella versions: +Python 3.8 -Python 3.7 ___ Python tracker

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-12 Thread Vedran Čačić
Vedran Čačić added the comment: I think Guido's mistake is relevant here. It tripped me too. Too much negatives, and "prune" is not really well-known verb. Besides, we already have str.splitlines' keepends, which works the opposite way. -- ___

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-12 Thread Guido van Rossum
Guido van Rossum added the comment: > except the other way around Whoops. Indeed. So all's well here. > x.split(tuple(string.whitespace)) Yes, that's what I was after. (But it can be a separate PR.) -- ___ Python tracker

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-12 Thread Emanuel Barry
Emanuel Barry added the comment: Barry: Sure, the docs example was just a quick write-up, you can word it however you want! Guido: Pretty much, except the other way around (when prune is False, i.e. "don't remove empty strings"). The attached patch exposes the behaviour (it's identical to

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-12 Thread Emanuel Barry
Changes by Emanuel Barry : Removed file: http://bugs.python.org/file45853/split_prune_1.patch ___ Python tracker ___

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-12 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: On Dec 12, 2016, at 04:16 PM, Guido van Rossum wrote: >So the proposal would be: prune=False -> empty strings stay, prune=True, >empty strings are dropped, prune=None (default) use True if sep is None, >False otherwise. Right? Yep! >Some end cases: > >-

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-12 Thread Guido van Rossum
Guido van Rossum added the comment: I like the proposal. I agree that filter(None, ...) is not discoverable (and has its own magic). So the proposal would be: prune=False -> empty strings stay, prune=True, empty strings are dropped, prune=None (default) use True if sep is None, False

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-12 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: I really appreciate all the feedback. Here are some thoughts. I'm well aware of the filter(), re, and other options, and certainly those can be made to work, but they're non-obvious. The reason I suggested an enhancement to str.split() is because I've seen

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: Guido, do you have an option on this? IIRC, this was an API you created. Nick's thought (posted on twitter) is that 'filter(None, sep.split(input)' already covers the "drop the empty values" case. My feelings are mixed. Though I've never needed in

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Vedran Čačić
Vedran Čačić added the comment: The problem with .split is its split (pun intended) personality: it really is two functions that have separate use cases, and have different algorithms; and people think about them as separate functions. In that view, we have just fallen afoul of Guido's rule

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Emanuel Barry
Emanuel Barry added the comment: Yes, I agree that being able to pass in a tuple would be really useful. As far as rolling out a custom function goes, I'd sooner reach for re.split than do that, so I don't really have a strong argument for either side. Feel free to play with the patch or make

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Sye van der Veen
Sye van der Veen added the comment: In the sep!=None case, there are existing alternatives to prune=True that aren't many more keystrokes: >>> ''.split(' ', prune=True) [] >>> [x for x in ''.split(' ') if x] [] >>> list(filter(bool, ''.split(' '))) # or drop list() and use the iterator >>>

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Emanuel Barry
Emanuel Barry added the comment: Here's an initial patch. It works exactly as discussed earlier, doesn't break any tests, and retains full backwards compatibility. No doc changes (except for the docstrings of str.[r]split) and no tests, as this is just a preliminary patch to see if there's

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Emanuel Barry
Emanuel Barry added the comment: Matthew: Yes, that's exactly the way I was going about it. Thank you Raymond for your comments (and your informative answer on that SO question). I think that part of the problem is that no delimiter (or None) behaves differently than with a delimiter. If we

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Raymond Hettinger
Raymond Hettinger added the comment: A few randomly ordered thoughts about splitting: * The best general purpose text splitter I've ever seen is in MS Excel and is called "Text to Columns". It has a boolean flag, "treat consecutive delimiters as one" which is off by default. * There is a

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Matthew Barnett
Matthew Barnett added the comment: So prune would default to None? None means current behaviour (prune if sep is None else don't prune) True means prune empty strings False means don't prune empty string -- nosy: +mrabarnett ___ Python tracker

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Emanuel Barry
Emanuel Barry added the comment: Actually, there might be a way. We could make prune default to True if sep is None, and default to False if sep is not None. That way, we get to keep the existing behaviour for either case, while satisfying both of our use cases :) If that's a bad idea (and it

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: On Dec 11, 2016, at 03:57 PM, Serhiy Storchaka wrote: >I meant adding boolean argument that changes the behavior when sep is None, >not when it is not None. Ah, I understand now, thanks. However, I'm not sure that addresses my particular use case. It's

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Emanuel Barry
Emanuel Barry added the comment: That would work for my case, but it wouldn't for Barry's (unless I missed something). He wants a non-None argument to not leave empty strings, but I want a None argument to leave empty strings... I don't think there's a one-size-fits-all solution in this case,

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I meant adding boolean argument that changes the behavior when sep is None, not when it is not None. -- ___ Python tracker

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Emanuel Barry
Emanuel Barry added the comment: Changing the behaviour when sep is None is a big backwards-compatibility break, and I'm not sure we'd even want that. It's logical to allow passing None to mean the same thing as NULL (i.e. no arguments), and the behaviour in that case has been like that

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Barry A. Warsaw
Barry A. Warsaw added the comment: On Dec 11, 2016, at 03:32 PM, Serhiy Storchaka wrote: >Current behavior is consistent with str.count(): > >len(string.split(sep)) == string.count(sep) + 1 > >and re.split(): > >re.split(re.escape(sep), string) == string.split(sep) Yep. My suggestion

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Current behavior is consistent with str.count(): len(string.split(sep)) == string.count(sep) + 1 and re.split(): re.split(re.escape(sep), string) == string.split(sep) May be the behavior when sep is None should be changed for consistency with the

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Emanuel Barry
Emanuel Barry added the comment: I understand the feeling. However, in a project I maintain, we want the other way around - to be able to never have an empty list, even if the string is empty (we resorted to using re.split in the end, which has this behaviour). Consider: rest = re.split("

[issue28937] str.split(): remove empty strings when sep is not None

2016-12-11 Thread Barry A. Warsaw
New submission from Barry A. Warsaw: This has finally bugged me enough to file an issue, although I wouldn't be able to use it until Python 3.7. There's a subtle but documented difference in str.split() when sep=None: >>> help(''.split) Help on built-in function split: split(...) method of