Best way to rewrite Popen

Chris Angelico rosuav at gmail.com
Tue May 19 14:13:53 EDT 2015


On Wed, May 20, 2015 at 3:55 AM, Zachary Ware
<zachary.ware+pylist at gmail.com> wrote:
>> def capture_stdout(*a, **kw):
>>     if 'stdout' not in kw: kw['stdout'] = subprocess.PIPE
>
> Just a quick note that this line can be simplified nicely to:
>
> kw.setdefault('stdout', subprocess.PIPE)

Yes, in the simple case. That does require pre-evaluating
subprocess.PIPE though, which in some situations is an important
distinction. But you're right, for something this simple, the
repetition is superfluous. Good catch.

ChrisA



More information about the Python-list mailing list