Package pygeodesy :: Module streprs |
[frames] | no frames]

# Module streprs

Floating point and other formatting utilities.

Version: 24.06.15

Functions
anstr(name, OKd=`'``._-``'`, sub='_') Make a valid name of alphanumeric and OKd characters. |
attrs(inst, *names, **Nones_True__pairs_kwds) Get instance attributes as name=value strings, with `float`s formatted by function fstr. |
enstr2(easting, northing, prec, *extras, **wide_dot) Return an MGRS/OSGR easting, northing string representations. |
fstr(floats, prec=6, fmt='F', ints=False, sep=', ', strepr=None, force=True) Convert one or more floats to string, optionally stripped of trailing zero decimals. |
fstrzs(efstr, ap1z=False) Strip trailing zero decimals from a `float` string. |
hstr(height, prec=2, fmt='%+.*f', ints=False, m='') Return a string for the height value. |
instr(inst, *args, **kwds) Return the string representation of an instantiation. |
lrstrip(txt, lrpairs=`{``'``(``'``:` `'``)``'``,` `'``<``'``:` `'``>``'``,` `'``[``'``:` `'``]``'``,` `'``{``'``:` `'``}``'``}`) Left- and right-strip parentheses, brackets, etc. |
pairs(items, prec=6, fmt='F', ints=False, sep='=') Convert items to name=value strings, with `float`s handled like fstr. |
reprs(objs, prec=6, fmt='F', ints=False) Convert objects to `repr` strings, with `float`s handled like fstr. |
strs(objs, prec=6, fmt='F', ints=False) Convert objects to `str` strings, with `float`s handled like fstr. |
unstr(where, *args, **kwds) Return the string representation of an invokation. |

Variables
| __all__ = `_ALL_LAZY.streprs`

Function Details

### anstr (name, OKd=`'``._-``'`, sub='_') |
Make a valid name of alphanumeric and OKd characters. Arguments: `name` - The original name (`str`). `OKd` - Other acceptable characters (`str`). `sub` - Substitute for invalid charactes (`str`). Returns: The modified name (`str`). Note: Leading and trailing whitespace characters are removed, intermediate whitespace characters are coalesced and substituted.

### attrs (inst, *names, **Nones_True__pairs_kwds) |
Get instance attributes as name=value strings, with `float`s formatted by function fstr. Arguments: `inst` - The instance (any `type`). `names` - The attribute names, all other positional (`str`). `Nones_True__pairs_kwds` - Keyword argument for function pairs, except `Nones=True` to in-/exclude missing or `None`-valued attributes. Returns: A `tuple(sep.join(t) for t in zip(names, reprs(values, ...)))` of `str`s.

### enstr2 (easting, northing, prec, *extras, **wide_dot) |
Return an MGRS/OSGR easting, northing string representations. Arguments: `easting` - Easting from false easting (`meter`). `northing` - Northing from from false northing (`meter`). `prec` - Precision, the number of decimal digits (`int`) or if negative, the number of units to drop, like MGRS PRECISION. `extras` - Optional leading items (`str`s). `wide_dot` - Optional keword argument `wide=5` for the number of unit digits (`int`) and `dot=False` (`bool`) to insert a decimal point. Returns: `extras` + 2-tuple `(str(easting), str(northing))` or + 2-tuple `("", "")` for `prec <= -wide`. Raises: `ValueError` - Invalid `easting`, `northing` or `prec`. Note: The `easting` and `northing` values are truncated, not rounded.

### fstr (floats, prec=6, fmt='F', ints=False, sep=', ', strepr=None, force=True) |
Convert one or more floats to string, optionally stripped of trailing zero decimals. Arguments: `floats` - Single or a list, sequence, tuple, etc. (`scalar`s). `prec` - The `float` precision, number of decimal digits (0..9). Trailing zero decimals are stripped if `prec` is positive, but kept for negative `prec` values. In addition, trailing decimal zeros are stripped for alternate, form '#'. `fmt` - Optional `float` format (`letter`). `ints` - Optionally, remove the decimal dot for `int` values (`bool`). `sep` - Separator joining the `floats` (`str`). `strepr` - Optional callable to format non-`floats` (typically `repr`, `str`) or `None` to raise a TypeError and used only if `force is not True`. `force` - If `True` format all `floats` using `fmt`, otherwise use `strepr` for non-`floats`. Returns: The `sep.join(strs(floats, ...)` joined (`str`) or single `strs((floats,), ...)` (`str`) if `floats` is `scalar`.

### fstrzs (efstr, ap1z=False) |
Strip trailing zero decimals from a `float` string. Arguments: `efstr` - Float with or without exponent (`str`). `ap1z` - Append the decimal point and one zero decimal if the `efstr` is all digits (`bool`). Returns: Float (`str`).

### hstr (height, prec=2, fmt='%+.*f', ints=False, m='') |
Return a string for the height value. Arguments: `height` - Height value (`float`). `prec` - The `float` precision, number of decimal digits (0..9). Trailing zero decimals are stripped if `prec` is positive, but kept for negative `prec` values. `fmt` - Optional `float` format (`letter`). `ints` - Optionally, remove the decimal dot for `int` values (`bool`). `m` - Optional unit of the height (`str`).

### instr (inst, *args, **kwds) |
Return the string representation of an instantiation. Arguments: `inst` - The instance (any `type`). `args` - Optional positional arguments. `kwds` - Optional keyword arguments. Returns: Representation (`str`).

### lrstrip (txt, lrpairs=`{``'``(``'``:` `'``)``'``,` `'``<``'``:` `'``>``'``,` `'``[``'``:` `'``]``'``,` `'``{``'``:` `'``}``'``}`) |
Left- and right-strip parentheses, brackets, etc. from a string. Arguments: `txt` - String to be stripped (`str`). `lrpairs` - Parentheses, etc. to remove (`dict` of one or several `(Left, Right)` pairs). Returns: Stripped `txt` (`str`).

### pairs (items, prec=6, fmt='F', ints=False, sep='=') |
Convert items to name=value strings, with `float`s handled like fstr. Arguments: `items` - Name-value pairs (`dict` or 2-{tuple}s of any `type`s). `prec` - The `float` precision, number of decimal digits (0..9). Trailing zero decimals are stripped if `prec` is positive, but kept for negative `prec` values. `fmt` - Optional `float` format (`letter`). `ints` - Optionally, remove the decimal dot for `int` values (`bool`). `sep` - Separator joining names and values (`str`). Returns: A `tuple(sep.join(t) for t in items))` of `str`s.

### reprs (objs, prec=6, fmt='F', ints=False) |
Convert objects to `repr` strings, with `float`s handled like fstr. Arguments: `objs` - List, sequence, tuple, etc. (any `type`s). `prec` - The `float` precision, number of decimal digits (0..9). Trailing zero decimals are stripped if `prec` is positive, but kept for negative `prec` values. `fmt` - Optional `float` format (`letter`). `ints` - Optionally, remove the decimal dot for `int` values (`bool`). Returns: A `tuple(map(fstr|repr, objs))` of `str`s.

### strs (objs, prec=6, fmt='F', ints=False) |
Convert objects to `str` strings, with `float`s handled like fstr. Arguments: `objs` - List, sequence, tuple, etc. (any `type`s). `prec` - The `float` precision, number of decimal digits (0..9). Trailing zero decimals are stripped if `prec` is positive, but kept for negative `prec` values. `fmt` - Optional `float` format (`letter`). `ints` - Optionally, remove the decimal dot for `int` values (`bool`). Returns: A `tuple(map(fstr|str, objs))` of `str`s.

### unstr (where, *args, **kwds) |
Return the string representation of an invokation. Arguments: `where` - Class, function, method (`type`) or name (`str`). `args` - Optional positional arguments. `kwds` - Optional keyword arguments, except `_fmt=Fmt.g` and `_ELLIPSIS=False`. Returns: Representation (`str`).