(value)
Parse a unit value

    Accepts:
    * An already converted instance of unit
    * An integer (interpreted as pixels)
    * A float (interpreted as pixels)
    * A string with a known unit suffix
    * A string containing an float (interpreted as pixels)
Parse a unit value
Parse a unit value
def units(value):
    """Parse a unit value

    Accepts:
    * An already converted instance of unit
    * An integer (interpreted as pixels)
    * A float (interpreted as pixels)
    * A string with a known unit suffix
    * A string containing an float (interpreted as pixels)
    """
    if isinstance(value, Unit):
        return value
    elif isinstance(value, (int, float)):
        return value * px
    elif isinstance(value, str):
        for suffix, unit in Unit.UNITS:
            if value.endswith(suffix):
                try:
                    return float(value[:-len(suffix)]) * unit
                except ValueError:
                    pass

        try:
            return float(value) * px
        except ValueError:
            pass

    raise ValueError('Unknown size %s' % value)
def units ( value ) : if isinstance ( value , Unit ) : return value elif isinstance ( value , ( int , float ) ) : return value * px elif isinstance ( value , str ) : for suffix , unit in Unit . UNITS : if value . endswith ( suffix ) : try : return float ( value [ : - len ( suffix ) ] ) * unit except ValueError : pass try : return float ( value ) * px except ValueError : pass raise ValueError ( 'Unknown size %s' % value )