0
我跑在python以下幾點:的Python /遍歷subprocess.check_output的內容 - 逐行
list_m = subprocess.check_output(command, shell=True).strip('\n')
當我打印,它給了我下面的內容:
Name region sort
b30 us large
b40 europe medium
祝爲了迭代每一行並僅打印第一個單詞,所以我將得到第一次迭代b30
以及第二次b40
。
我嘗試遍歷list_m
:
for i in list_m
print i
,它給了我下面的:
N
a
m
e
r
e
,並持續到中等。
如何迭代輸出每行,並打印第一個單詞?
'.split('')[0]'? –
您已經可以遍歷這些行。現在,只需'分割()'每行並打印第一個元素。 – ForceBru