Python itertools: Cartesian product with filtering of empty strings
<p>I'm writing a script to call a program with all possible command-line arguments. Some of these arguments can be not present. Attempt #1:</p>

<pre><code>args1 = ['program.exe']
args2 = ['1', '5', '']
args3 = ['--foo', '']
for args in itertools.product(args1, args2, args3):
    args = [arg for arg in args if arg != '']
    subprocess.call(list(args))
</code></pre>

<p>Is there another way to get these permutations without having to manually filter out the empty string? Things break if I just leave it in the argument list. I mean, my approach works, but I feel like there would be some more built-in way to handle this. Although reading <a href="https://stackoverflow.com/questions/27891032/python-cartesian-product-and-conditions" title="this">this question</a> is making me think that's less likely.</p>