Class for holding data about a parameter.
Methods
|
|
__init__
__repr__
__str__
_handle_unit
_scan
get
getPhysicalQuantity
get_wunit
set
|
|
__init__
|
__init__ (
self,
name=None,
default=0.0,
str2type=None,
help=None,
unit=None,
cmlarg=None,
)
default default value
str2type string to type conversion
name parameter name
help description of parameter
unit physical unit (dimension)
cmlarg command-line argument for sending
this prm to an external program Note: value with unit only works if str is float or int
>>> p=InputPrm(q , 1, float, unit=m )
>>> p.set(6)
>>> p.get()
6.0
>>> p.set(6 cm )
>>> p.get()
0.059999999999999998
>>> p=InputPrm(q , 1 m , float, unit=m )
>>> p.set(1 km )
>>> p.get()
1000.0
>>> p.get_wunit()
1000.0 m
>>> p.unit
m
Exceptions
|
|
ValueError, 'str2type must be float or int, not %s' % str( self.str2type )
ValueError, 'unit=%s is an illegal physical unit' % str( self.unit )
|
|
|
__repr__
|
__repr__ ( self )
Application of eval to this output creates the instance.
|
|
__str__
|
__str__ ( self )
Compact output; just the value as a formatted string.
Note that __str__ is used by __repr__ so strings must
be enclosed in quotes.
|
|
_handle_unit
|
_handle_unit ( self, v )
Check if v is of the form value unit , extract value, after
conversion to correct unit (if necessary).
Exceptions
|
|
ValueError, '%s should be %s; illegal syntax' %( v, self.str2type.__name__ )
ValueError, 'illegal unit (%s); %s is registered with unit %s' %( v, self.name, self.unit )
ValueError, 'parameter %s given with dimension: %s, but ' 'dimension is not registered' %( self.name, v )
|
|
|
_scan
|
_scan ( self, s )
Interpret string s. Return number (for self._v).
|
|
get
|
get ( self )
Return the value of the parameter.
|
|
getPhysicalQuantity
|
getPhysicalQuantity ( self )
Exceptions
|
|
AttributeError, 'parameter %s has no registered unit' % self.name
|
|
|
get_wunit
|
get_wunit ( self )
Return value with unit (dimension) as string, if it has.
Otherwise, return value (with the right type).
|
|
set
|
set ( self, value )
Set the value of the parameter.
|
|