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

# Module streprs

Floating point and other formatting utilities.

Version: 20.03.23

Functions
anstr(name, OKd=`'``._-``'`, sub=`'``_``'`) Make a valid name of alphanumeric and OKd characters. |
attrs(inst, *names, **kwds) Get instance attributes as name=value strings, with `float`s handled like fstr. |
enstr2(easting, northing, prec, *extras) Return easting, northing string representations. |
fstr(floats, prec=6, fmt=`'``F``'`, ints=False, sep=`'``,` `'`) Convert one or more floats to string, optionally stripped of trailing zero decimals. |
fstrzs(efstr) Strip trailing zero decimals from a `float` string. |
instr(inst, *args, **kwds) Return the string representation of an instantion. |
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(name, *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 and intermediate whitespace characters are coalesced and substituted.

### attrs (inst, *names, **kwds) |
Get instance attributes as name=value strings, with `float`s handled like fstr. Arguments: `inst` - The instance (any `type`). `names` - The attribute names (`str`s). `kwds` - Keyword argument for function pairs, except `Nones=True` to in-/exclude missing or attributes with a `None` value. 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`). `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=`'``,` `'`) |
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. `fmt` - Optional, float format (`str`). `ints` - Optionally, remove the decimal dot (`bool`). `sep` - Separator joining the `floats` (`str`). Returns: The `sep.join(strs(floats, ...)` joined (`str`) or single `strs((floats,), ...)` (`str`) if `floats` is `scalar`.

### fstrzs (efstr) |
Strip trailing zero decimals from a `float` string. Arguments: `efstr` - Float with or without exponent (`str`). Returns: Float (`str`).

### instr (inst, *args, **kwds) |
Return the string representation of an instantion. 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 (`bool`). `sep` - Separator joining names and values (`str`). Returns: A `tuple(sep.join(t) for t in zip(names, reprs(values,...)))` 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 (`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 (`bool`). Returns: A `tuple(map(fstr|str, objs))` of `str`s.

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