Changeset 266 for etherws


Ignore:
Timestamp:
12/07/13 03:18:24 (11 years ago)
Author:
atzm
Message:

use operator.attrgetter() instead of using cmp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • etherws/trunk/etherws.py

    r265 r266  
    5050import hashlib 
    5151import getpass 
     52import operator 
    5253import argparse 
    5354import traceback 
     
    188189            self.shut = False 
    189190 
    190         @staticmethod 
    191         def cmp_by_number(x, y): 
    192             return cmp(x.number, y.number) 
    193  
    194191    def __init__(self, fdb, debug): 
    195192        self.fdb = fdb 
     
    200197    @property 
    201198    def portlist(self): 
    202         return sorted(self._table.itervalues(), cmp=self.Port.cmp_by_number) 
     199        return sorted(self._table.itervalues(), 
     200                      key=operator.attrgetter('number')) 
    203201 
    204202    def get_port(self, portnum): 
     
    223221        ports = (self._table[n] for n in portnums) 
    224222        ports = (p for p in ports if not p.shut) 
    225         ports = sorted(ports, cmp=self.Port.cmp_by_number) 
     223        ports = sorted(ports, key=operator.attrgetter('number')) 
    226224 
    227225        for p in ports: 
Note: See TracChangeset for help on using the changeset viewer.