NamedUnit

class astropy.units.core.NamedUnit(st, register=False, doc=None, format=None) [edit on github][source]

Bases: astropy.units.core.UnitBase

The base class of units that have a name.

Parameters :

st : str or list of str

The name of the unit. If a list, the first element is the canonical (short) name, and the rest of the elements are aliases.

register : boolean, optional

When True, also register the unit in the standard unit namespace. Default is False.

doc : str, optional

A docstring describing the unit.

format : dict, optional

A mapping to format-specific representations of this unit. For example, for the Ohm unit, it might be nice to have it displayed as \Omega by the latex formatter. In that case, format argument should be set to:

{'latex': r'\Omega'}
Raises :

ValueError :

If any of the given unit names are already in the registry.

ValueError :

If any of the given unit names are not valid Python tokens.

Attributes Summary

name Returns the canonical (short) name associated with this unit.
names Returns all of the names associated with this unit.
aliases Returns the alias (long) names for this unit.

Methods Summary

get_format_name(format) Get a name for this unit that is specific to a particular format.

Attributes Documentation

name[source]

Returns the canonical (short) name associated with this unit.

names[source]

Returns all of the names associated with this unit.

aliases[source]

Returns the alias (long) names for this unit.

Methods Documentation

get_format_name(format) [edit on github][source]

Get a name for this unit that is specific to a particular format.

Uses the dictionary passed into the format kwarg in the constructor.

Parameters :

format : str

The name of the format

Returns :

name : str

The name of the unit for the given format.

Page Contents