ubuntu - How do I update the modules that come with python? -


i having trouble subprocess module. missing check_output function , wondering if there way update/replace without doing complete reinstall of python.

yes, it's possible, can add function in if necessary (only suggested if need backwards capability).

if 'check_output' not in dir(subprocess):     def check_output(cmd_args, *args, **kwargs):         proc = subprocess.popen(             cmd_args, *args,             stdout=subprocess.pipe, stderr=subprocess.pipe, **kwargs)         out, err = proc.communicate()         if proc.returncode != 0:             raise subprocess.calledprocesserror(args)         return out     subprocess.check_output = check_output 

but code shows, can write little more verbosely , doesn't operate differently.

edit: copy directly subprocess module version python 2.7

def check_output(*popenargs, **kwargs):     if 'stdout' in kwargs:         raise valueerror('stdout argument not allowed, overridden.')     process = subprocess.popen(stdout=subprocess.pipe, *popenargs, **kwargs)     output, unused_err = process.communicate()     retcode = process.poll()     if retcode:         cmd = kwargs.get("args")         if cmd none:             cmd = popenargs[0]         raise subprocess.calledprocesserror(retcode, cmd, output=output)     return output 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -