astropy/astropy — pull request #1462 by alexrudy (2013-09-16 22:42:26+00:00)
Title: Unit format specifiers

This is an addendum to #1383 which uses the format code specifier to select a units formatter. There are probably much more complicated things which could be done here, but it does allow for the following:

```python
In [1]: import astropy.units as u

In [2]: "{:generic}".format(u.degree)
Out[2]: 'deg'

In [3]: u"{:unicode}".format(u.degree)
Out[3]: u'\xb0'

In [4]: u"{:latex}".format(u.degree)
Out[4]: u'$\\mathrm{{}^{\\circ}}$'
```

Very simply, this check to see if the specifier is a valid unit formatter, if so, that unit formatter is used. If not, the specifier is treated as a string formatter for the generic unit form.