Did I find the right examples for you? yes no

All Samples(3)  |  Call(2)  |  Derive(0)  |  Import(1)
Return a list of matching units names.
if quantity is a string -- units containing the string `quantity`
if quantity is a unit -- units having matching base units

Examples
========

>>> from sympy.physics import units as u
>>> u.find_unit('charge')
['charge'](more...)

        def find_unit(quantity):
    """
    Return a list of matching units names.
    if quantity is a string -- units containing the string `quantity`
    if quantity is a unit -- units having matching base units

    Examples
    ========

    >>> from sympy.physics import units as u
    >>> u.find_unit('charge')
    ['charge']
    >>> u.find_unit(u.charge)
    ['C', 'charge', 'coulomb', 'coulombs']
    >>> u.find_unit('volt')
    ['volt', 'volts', 'voltage']
    >>> u.find_unit(u.inch**3)[:5]
    ['l', 'cl', 'dl', 'ml', 'liter']
    """
    import sympy.physics.units as u
    rv = []
    if isinstance(quantity, str):
        rv = [i for i in dir(u) if quantity in i]
    else:
        units = quantity.as_coeff_Mul()[1]
        for i in dir(u):
            try:
                if units == eval('u.' + i).as_coeff_Mul()[1]:
                    rv.append(str(i))
            except:
                pass
    return sorted(rv, key=len)
        


src/s/y/sympy-HEAD/sympy/physics/tests/test_units.py   sympy(Download)
from sympy import integrate, Rational, sqrt, Symbol
from sympy.physics.units import (au, amu, charge, day, find_unit,
                                 foot, km, m, meter, minute, s,
                                 speed_of_light, grams, quart, inch)
 
def test_find_unit():
    assert find_unit('charge') == ['charge']
    assert find_unit(charge) == ['C', 'charge', 'coulomb', 'coulombs']