cf.Units.formatted

Units.formatted(names=None, definition=None)[source]

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:
names : bool, optional

Use unit names instead of symbols.

definition : bool, optional

The formatted string is given in terms of basic-units instead of stopping any expansion at the highest level possible.

Returns:
out : str

The formatted string.

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'

Previous topic

cf.Units.equivalent

Next topic

cf.Units.log

This Page