python: basics 
get all the processes on system


import sys
my_process = os.popen("ps -ef")
for program in my_process.readlines():
print program[:-1]


make list from processes / per line, separate fields to list, print one field from lists


import os
import sys
import strings
my_process = os.popen("ps -ef")
for program in my_process.readlines():
program = program[:-1].split()
program[7]


write as function, return all programs running


import os
import sys
import strings

def list_programs():
list = []
for program in os.popen("ps -ef").readlines():
program = program[:-1].split()
list.append(program[7])
return list

if __name__ == "__main__":
for pgm in list_programs():
print pgm



using classess


class acl:
readgroups = []
def readwho(self):
print self.readgroups

newc = acl()
newc.readgroups = [ "aaaa" ]
newc.readwho()
['aaaa']


nesting classess


class allattrs(acl,version):
''' just a class '''
ou = allattrs()
ou.version="2"
ou.version
'2'




[ add comment ] ( 8 views )   |  [ 0 trackbacks ]   |  permalink

<<First <Back | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | Next> Last>>