Message284894
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.) |
|
Date |
User |
Action |
Args |
2017-01-07 06:49:43 | berker.peksag | set | recipients:
+ berker.peksag, vinay.sajip, r.david.murray, docs@python, marco.buttu, evan_ |
2017-01-07 06:49:43 | berker.peksag | set | messageid: <1483771783.19.0.436198408517.issue29133@psf.upfronthosting.co.za> |
2017-01-07 06:49:43 | berker.peksag | link | issue29133 messages |
2017-01-07 06:49:42 | berker.peksag | create | |
|