Pythonでターミナルの出力を取得する

http://stackoverflow.com/questions/3503879/assign-output-of-os-system-to-a-variable-and-prevent-it-from-being-displayed-on

import commands
status, output = commands.getstatusoutput("cat /etc/services")

>>> import commands
>>> status, output = commands.getstatusoutput("lpstat -s")
>>> print output

system default destination: OKI_MC860_3BB60A
device for _133_11_88_31: lpd://133.11.88.31:58147/
device for _192_168_1_80: lpd://192.168.1.80/
device for Brother_MFC_9460CDN: usb://Brother/MFC-9460CDN?serial=E68940H1J211148
device for EPSON_PX_7000: usb://EPSON/PX-7000?serial=NE0020206061041020
device for EPSON_PX_9500S: usb://EPSON/PX-9500S?serial=NE055070109102011-
device for HP_Officejet_100_Mobile_L411: usb://HP/Officejet%20100%20Mobile%20L411?serial=MY16S511G7
device for OKI_MC860_3BB60A: dnssd://OKI-MC860-3BB60A._pdl-datastream._tcp.local./?bidi
device for Roland_iM-01: usb://Roland/iM-01?serial=A


>>> printers = output.split("\n")
>>> printers
['system default destination: OKI_MC860_3BB60A', 'device for _133_11_88_31: lpd://133.11.88.31:58147/', 
'device for _192_168_1_80: lpd://192.168.1.80/', 'device for Brother_MFC_9460CDN: usb://Brother/MFC-9460CDN?serial=E68940H1J211148', 
'device for EPSON_PX_7000: usb://EPSON/PX-7000?serial=NE0020206061041020', 
'device for EPSON_PX_9500S: usb://EPSON/PX-9500S?serial=NE055070109102011-',
 'device for HP_Officejet_100_Mobile_L411: usb://HP/Officejet%20100%20Mobile%20L411?serial=MY16S511G7', 
'device for OKI_MC860_3BB60A: dnssd://OKI-MC860-3BB60A._pdl-datastream._tcp.local./?bidi', 
'device for Roland_iM-01: usb://Roland/iM-01?serial=A']
>>> [printer.split("device for")[1].split(":")[0].strip() for printer in printers if "device for" in printer]
['_133_11_88_31', '_192_168_1_80', 'Brother_MFC_9460CDN', 'EPSON_PX_7000', 'EPSON_PX_9500S', 'HP_Officejet_100_Mobile_L411', 'OKI_MC860_3BB60A', 'Roland_iM-01']