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

# Module streprs

Floating point and other formatting utilities.

Version: 20.03.12

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 floats handled like fstr. |
enstr2(easting, northing, prec, *extras) Return easting, northing string representations. |
fstr(floats, prec=6, fmt=`'``F``'`, ints=False, sep=`'``,` `'`) Convert 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 floats handled like fstr. |
reprs(objs, prec=6, fmt=`'``F``'`, ints=False) Convert objects to `repr` strings, with floats handled like fstr. |
strs(objs, prec=6, fmt=`'``F``'`, ints=False) Convert objects to `str` strings, with floats 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. Parameters: `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 floats handled like fstr. Parameters: `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. Parameters: `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 floats to string, optionally stripped of trailing zero decimals. Parameters: `floats` - List, sequence, tuple, etc. (`scalar`s or `scalar`). `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, ...)` string or a single `strs((floats,), ...)` if `floats` is `scalar` (`str`).

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

### instr(inst, *args, **kwds) |
Return the string representation of an instantion. Parameters: `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 floats handled like fstr. Parameters: `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 floats handled like fstr. Parameters: `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 floats handled like fstr. Parameters: `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. Parameters: `name` - Function, method or class name (`str`). `args` - Optional positional arguments. `kwds` - Optional keyword arguments. Returns: Representation (`str`).