Wie extrahiere ich eine Spalte aus Text mit Python?Python

Python-Programme
Anonymous
 Wie extrahiere ich eine Spalte aus Text mit Python?

Post by Anonymous »

Könnte jemand mir bitte helfen, nur die zweite Spalte als Ausgabe des Befehls PS Aux zu erhalten (d. H. Nur die Spalte ).

Code: Select all

# script to print the processid
import os
import commands

out = commands.getoutput('ps aux')  # to get the process listing in out
# print out
# print out[2]  # print only second column from out
print out[:2]
Ausgabe des Drucks Anweisung

Code: Select all

    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0   5728  1068 ?        Ss   Oct13   0:07 /sbin/init
root         2  0.0  0.0      0     0 ?        S<   Oct13   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S<   Oct13   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S<   Oct13   0:11 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S<   Oct13   0:00 [watchdog/0]
root         6  0.0  0.0      0     0 ?        S<   Oct13   0:00 [migration/1]
Danke im Voraus

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post