Question

when i try to do git push using subprocess.Popen

        msg, err = subprocess.Popen('git push', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        print msg.stdout.read()

i get error saying : TypeError: 'Popen' object is not iterable

Was it helpful?

Solution

You're treating it like an iterable:

msg, data = ..

This will try to loop over the object and assigning the items to msg and data. Since the object returned is not an iterable, you have the error.

The subprocess.Popen constructor returns a Popen object. Maybe you want to use Popen.communicate? It does return a tuple, stdoutdata, stderrdata.

OTHER TIPS

The code

msg, err = X

will iterate over X and assign its first element to msg and its second element to err (and check that X has exactly 2 elements).

Since Popen instance is not an iterable your code throws "'Popen' object is not iterable".

Popen() returns not an iterable, but a Popen instance.

when you say a,b = thing, you assume thing is a tuple (or other iterable) which can be mapped to (a, b)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top