User Tools

Site Tools


programming:python:pspackage

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
programming:python:pspackage [2008/04/30 19:00]
crustymonkey
programming:python:pspackage [2009/12/17 21:04] (current)
newacct
Line 107: Line 107:
         """​         """​
         for row in self._rows:         for row in self._rows:
-            if not '​pid'​ in row:+            if '​pid' ​not in row:
                 return None                 return None
             if int(row.pid) == int(pid):             if int(row.pid) == int(pid):
Line 119: Line 119:
         ret = []         ret = []
         for row in self._rows:         for row in self._rows:
-            if not '​user'​ in row:+            if '​user' ​not in row:
                 return None                 return None
             if row.user == username:             if row.user == username:
Line 133: Line 133:
         reg = re.compile(search)         reg = re.compile(search)
         for row in self._rows:         for row in self._rows:
-            if not '​command'​ in row:+            if '​command' ​not in row:
                 return None                 return None
             if reg.search(row.command):​             if reg.search(row.command):​
Line 179: Line 179:
         items = re.split(r'​\s+'​ , s.strip() , len(self.cols) - 1)         items = re.split(r'​\s+'​ , s.strip() , len(self.cols) - 1)
         self.items = dict(zip(self.cols , items))         self.items = dict(zip(self.cols , items))
-        self.__dict__ ​= dict(self.__dict__ , **self.items)+        self.__dict__.update(self.items)
         ​         ​
     def __contains__(self , k):     def __contains__(self , k):
Line 190: Line 190:
                 print psrow.user                 print psrow.user
         """​         """​
-        return self.items.has_key(k)+        return ​k in self.items
     ​     ​
     def __iter__(self):​     def __iter__(self):​
Line 210: Line 210:
             print psrow['​user'​]             print psrow['​user'​]
         """​         """​
-        if self.items.has_key(name):+        if name in self.items:
             return self.items[name]             return self.items[name]
 </​code>​ </​code>​
Line 224: Line 224:
 # Show each running process as a block # Show each running process as a block
 for row in myps: for row in myps:
-    for col in row: +    for col, val in row.items()
-        print '%s: %s' % (col , row[col])+        print '%s: %s' % (col , val)
     print     print
 </​code>​ </​code>​
programming/python/pspackage.txt · Last modified: 2009/12/17 21:04 by newacct