1 #!/usr/bin/env python 2 3 import os 4 import string 5 6 #方法1:通过字符串的isdigits来判断 7 #filelist = os.listdir('/proc') 8 # 9 #for pid in filelist: 10 # if pid.isdigit(): 11 # print pid 12 13 # 方法2:通过定义函数来判断 14 def isNum(pid): 15 for num in pid: 16 if num in string.digits: 17 continue 18 else: 19 return False 20 return True 21 22 for pid in os.listdir('/proc'): 23 if isNum(pid): 24 print pid