Berker Peksag added the comment: I'd probably write it without the for loop:
text = "a && b; c && d || e; f >'abc'; (def \"ghi\")" result = shlex.shlex(text) print(f"Old behavior: {list(result)}") result = shlex.shlex(text, punctuation_chars=True) print(f"New behavior: {list(result)}") Or just: >>> import shlex >>> text = "a && b; c && d || e; f >'abc'; (def \"ghi\")" >>> list(shlex.shlex(text)) ['a', '&', '&', 'b', ';', 'c', '&', '&', 'd', '|', '|', 'e', ';', 'f', '>', "'abc'", ';', '(', 'def', '"ghi"', ')'] >>> list(shlex.shlex(text, punctuation_chars=True)) ['a', '&&', 'b', ';', 'c', '&&', 'd', '||', 'e', ';', 'f', '>', "'abc'", ';', '(', 'def', '"ghi"', ')'] (Adding Vinay to nosy list to get his feedback since he wrote the original example.) ---------- nosy: +berker.peksag, vinay.sajip stage: -> patch review type: -> behavior _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue29133> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com