Here is the situation:
I've got a command I'm running:
import subprocess
foo = subprocess.Popen('ls /', shell=True, stdout=subprocess.PIPE,\
stderr=subprocess.STDOUT)
Pretty basic, right? And I've figured out that I can do stuff with the output with .communicate(), like this:
print foo.communicate()
Which works great and produces the output that the documentation for subprocess.communicate suggests it should, a tuple:
('bin\nboot\ncdrom\n[...stuff redacted for brevity...]tmp\nusr\nvar\nvmlinuz\n', None)
Notice the \n newlines in there. And I've discovered that just asking for the first element of the tuple produces output with newlines, like this:
>>> print foo.communicate()[0]
bin
boot
cdrom
[...stuff redacted for brevity...]
tmp
usr
var
vmlinuz
But what I don't understand is WHY printing with just the first element produces the newlines. Don't get me wrong, it is great, and I'm glad I can do it without a loop, but I'd like to understand what is going on.
Thanks in advance,
--jed