Message284894
| Author |
berker.peksag |
| Recipients |
berker.peksag, docs@python, evan_, marco.buttu, r.david.murray, vinay.sajip |
| Date |
2017年01月07日.06:49:42 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1483771783.19.0.436198408517.issue29133@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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.) |
|