Changeset 120

Show
Ignore:
Timestamp:
02/13/08 13:21:31 (9 months ago)
Author:
edsuom
Message:

Improvements to pybywire.params

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/Twisted-Goodies/trunk/twisted_goodies/pybywire/params.py

    r114 r120  
    114114        """ 
    115115        Sets the attribute I{name} to the supplied I{value}, clearing the cache 
    116         if the attribute is a parameter
     116        if the attribute is a parameter and its value will be (re)defined
    117117        """ 
    118118        if name in self.paramNames or name in self.keyAttrs: 
    119             self.cache.clear() 
     119            if not hasattr(self, name): 
     120                isDifferent = True 
     121            else: 
     122                isDifferent = (getattr(self, name) != value) 
     123                # Account for the possibility that one value is a Numpy array 
     124                if hasattr(isDifferent, 'any'): 
     125                    isDifferent = isDifferent.any() 
     126            if isDifferent: 
     127                self.cache.clear() 
    120128        object.__setattr__(self, name, value) 
     129 
     130    def N_params(self): 
     131        """ 
     132        Returns the number of parameters. Override this if you have some other 
     133        parameters figured in somehow. 
     134        """ 
     135        return len(self.paramNames) 
    121136 
    122137    def setParams(self, **kw): 
     
    128143                raise LookupError("No such parameter '%s'" % name) 
    129144            setattr(self, name, value) 
     145 
     146    def paramVector(self): 
     147        """ 
     148        Returns my entire current set of parameters as a sequence. 
     149        """ 
     150        return [getattr(self, name) for name in self.paramNames] 
    130151 
    131152    def setParamVector(self, paramVector):