On 03Apr2016 14:24, Steven D'Aprano <st...@pearwood.info> wrote:
On Sun, 3 Apr 2016 01:29 pm, Hongyi Zhao wrote:
I use the following code to update the os.environ with subprocess.Popen:
I don't understand what you are trying to do here. But regardless of your
intention, the problem you have is nothing to do with updating os.environ.
Proof: change the last line from this complicated expression:
os.environ.update(line.partition('=')[::2] for line in output.split('\0'))
to this simple expression:
output.split('\0')
and you will get the same error. os.environ is irrelevant. Your problem is
only with Popen.
What makes you think that Popen objects have a split() method? They are not
documented as having this method:
https://docs.python.org/2/library/subprocess.html
https://docs.python.org/3/library/subprocess.html
https://pymotw.com/2/subprocess/
In particular, you want the subprocess' output. As written, your code sets
"output" to the Popen object. You actually want to set it to the .stdout
attribute of that object, which is the output from the subcommand.
Cheers,
Cameron Simpson <c...@zip.com.au>
--
https://mail.python.org/mailman/listinfo/python-list