Skip to main content
`Ctrl`+`K`

# Base

class astropy.units.format.Base(*args, **kwargs)

  Bases: `object`

  The abstract base class of all unit formats.

  Attributes Summary

  `registry` |

  Methods Summary

  `format_exponential_notation`(val[, format_spec]) | Formats a value in exponential notation.
  `parse`(s) | Convert a string to a unit object.
  `to_string`(unit, *[, fraction]) | Convert a unit to its string representation.

  Attributes Documentation

  registry = {'cds': <class 'astropy.units.format.cds.CDS'>, 'console': <class 'astropy.units.format.console.Console'>, 'fits': <class 'astropy.units.format.fits.FITS'>, 'generic': <class 'astropy.units.format.generic.Generic'>, 'latex': <class 'astropy.units.format.latex.Latex'>, 'latex_inline': <class 'astropy.units.format.latex.LatexInline'>, 'ogip': <class 'astropy.units.format.ogip.OGIP'>, 'unicode': <class 'astropy.units.format.unicode_format.Unicode'>, 'vounit': <class 'astropy.units.format.vounit.VOUnit'>}

  Methods Documentation

  classmethod format_exponential_notation(val, format_spec='.8g')

    Formats a value in exponential notation.

    Parameters:
      val number

        The value to be formatted

      format_spec `python:str`, optional

        Format used to split up mantissa and exponent

    Returns:
      `python:str`

        The value in exponential notation in a this class’s format.

  classmethod parse(s)

    Convert a string to a unit object.

  classmethod to_string(unit, *, fraction=True)

    Convert a unit to its string representation.

    Implementation for `to_string`.

    Parameters:
      unit|Unit|

        The unit to convert.

      fraction{False|True|’inline’|’multiline’}, optional

        Options are as follows:

        - `False` : display unit bases with negative powers as they are (e.g., `km s-1`);

        - ‘inline’ or `True` : use a single-line fraction (e.g., `km / s`);

        - ‘multiline’ : use a multiline fraction if possible (available for the `latex`, `console` and `unicode` formats; e.g., `$\mathrm{\frac{km}{s}}$`). If not possible, use ‘inline’.

    Raises:
      `ValueError`

        If `fraction` is not recognized.