Q:

Issue with equal signs and function parameters

I'm trying to build a function that would allow to repeat this (it prevents the console from opening in windows):
 if platform.system() == 'Windows':
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        subprocess.call(['myprogram.exe', '-P', arg], 
                       stdout=someFile, startupinfo=startupinfo)
    else:
        subprocess.call(['myprogram.exe', '-P', arg], stdout=someFile)

Therefore I defined the following function:
def noWinConsole(program):
    if platform.system() == 'Windows':
        startupinfo = subprocess.STARTUPINFO()
        startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
        subprocess.call(program, startupinfo=startupinfo)
    else:
        subprocess.call(program)

But when I call it like this noWinConsole(['myprogram.exe', '-P', arg], stdout=someFile) , I get an error because of stdout=somefile:
TypeError: noWinConsole() got an unexpected keyword argument 'stdout'

How can I fix this ?

A:

noWinConsole is just a wrapper, and as it stands it's expecting just a single argument, program. Thus it freaks out when you give it two arguments (program as the first positional argument, and then the keyword argument stdout intended for the subprocess call). 
Luckily, there's a standard idiom for producing a wrapper that passes along any set of arguments to an inner function. It uses the * and ** notation for argument packing/unpacking.
def noWinConsole(*args, **kwargs):
    # Other stuff here as needed
    subprocess.call(*args, **kwargs)

What this does is basically this. The * operator in the function definition takes all the input positional arguments, and packs them into a tuple called args. Then when you call subprocess, the * operator unpacks that tuple, passing in those same arguments in the same order to the next function. 
The ** operator works essentially the same way, except that it catches keyword arguments like stdout='foo.txt' and packs all of them into a dictionary like {'stdout':'foo.txt'}. This dictionary is then unpacked and converted back into keyword arguments when you use the ** again in your call to the inner function.

