Ciasto piekarz
Ciasto piekarz

Reputation: 8277

why is subprocess popen giving typeError

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

Answers (3)

aIKid
aIKid

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

knitti
knitti

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

Nigel Tufnel
Nigel Tufnel

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

Related Questions