[Tutor] Fwd: print a for loop system call

Derek Smith DerekSmith at racksquared.com
Sat Jan 20 13:26:31 EST 2018



Sent from my iPhone

Begin forwarded message:

From: Derek Smith <DerekSmith at racksquared.com<mailto:DerekSmith at racksquared.com>>
Date: January 19, 2018 at 4:01:58 PM EST
To: "tutor-request at python.org<mailto:tutor-request at python.org>" <tutor-request at python.org<mailto:tutor-request at python.org>>
Subject: print a for loop system call

Why does A work but B does not?


#!/usr/bin/env python3

import os
import sys
from subprocess import Popen, PIPE

pipe = Popen('lsdev -c tape', shell=True, stdout=PIPE)

for dev in pipe.stdout :
    print ( dev.strip().split()[0].decode() )    ## A ##
    # print ( dev.strip().split().decode()[0] ) ## B ##


And if I try to store in an array using

rmts = [ dev.strip().split()[0].decode() ]

it only stores the last line when there are over 100 lines.

Sample line looks like

rmt144 Available 04-T1-01 LTO Ultrium Tape Drive (FCP)

thank you!

Derek Smith  |  Unix/TSM Administrator  | Racksquared Data Centers
':  614-437-4983 * 325 East Spring Street, Columbus, OH 43215
::  dereksmith at racksquared.com<mailto:dereksmith at racksquared.com>  *: www.racksquared.com<http://www.racksquared.com/> |  www.racksquared.jobs<http://www.racksquared.jobs/>

[cid:image003.png at 01D2E9AA.1B9CF8F0]



More information about the Tutor mailing list