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

# Module streprs

Floating point and other formatting utilities.

Version: 22.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) Return easting, northing string representations. |
fstr(floats, prec=6, fmt='F', ints=False, sep=', ', strepr=None) 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. |
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(named, *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) |
Return easting, northing string representations. Arguments: `easting` - Easting from false easting (`meter`). `northing` - Northing from from false northing (`meter`). `prec` - Precision in number of digits (`int`, 2..10). `extras` - Optional leading items (`str`s). Returns: `extras` + 2-Tuple `(eastingStr, northingStr)`. Raises: `ValueError` - Invalid `prec`.

### fstr (floats, prec=6, fmt='F', ints=False, sep=', ', strepr=None) |
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 (`str`). `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. 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 (`str`). `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`).

### 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 (`str`). `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 (`str`). `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 (`str`). `ints` - Optionally, remove the decimal dot for `int` values (`bool`). Returns: A `tuple(map(fstr|str, objs))` of `str`s.

### unstr (named, *args, **kwds) |
Return the string representation of an invokation. Arguments: `named` - Function, method or class name (`str`). `args` - Optional positional arguments. `kwds` - Optional keyword arguments. Returns: Representation (`str`).