Reputation: 8277
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
Upvotes: 0
Views: 2742
Reputation: 28242
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
.
Upvotes: 2
Reputation: 7033
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)
Upvotes: 1
Reputation: 11524
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".
Upvotes: 1