Formats the string stored in the units attribute in a standardized manner. The units attribute is modified in place and its new value is returned.
Parameters: |
|
---|---|
Returns: |
|
Examples: |
>>> u = Units('W')
>>> u.units
'W'
>>> u.units = u.format(names=True)
>>> u.units
'watt'
>>> u.units = u.format(definition=True)
>>> u.units
'm2.kg.s-3'
>>> u.units = u.format(names=True, definition=True)
'meter^2-kilogram-second^-3'
>>> u.units = u.format()
>>> u.units
'W'
>>> u.units='dram'
>>> u.format(names=True)
'1.848345703125e-06 meter^3'
Formatting is also available during object initialization:
>>> u = Units('m/s', format=True)
>>> u.units
'm.s-1'
>>> u = Units('dram', names=True)
>>> u.units
'1.848345703125e-06 m3'
>>> u = Units('W', names=True, definition=True)
>>> u.units
'meter^2-kilogram-second^-3'