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

# Module basics

Basic definitions, decorators and functions.

Version: 20.09.26

Classes
| property_RO

Functions
bool |
isinf(x) Check if float x is infinite (positive or negative). |
bool |
isnan(x) Check if float x is not a number (NaN). |
clips(bstr, limit=50, white=`'````'`) Clip a string to the given length limit. |
halfs2(str2) Split a string in 2 halfs. |
isclass(obj) Return `True` if `obj` is a `class`. |
isfinite(obj) Check for `Inf` and `NaN` values. |
isidentifier(obj) Return `True` if `obj` is a valid Python identifier. |
isint(obj, both=False) Check for `int` type or an integer `float` value. |
iskeyword(x, y) y in x. |
isneg0(obj) Check for NEG0, negative 0.0. |
isscalar(obj) Check for scalar types. |
issequence(obj, *excluded) Check for sequence types. |
isstr(obj) Check for string types. |
issubclassof(Sub, Super) Check whether a class is a sub-class of a super class. |
joined(*words, **sep) Joined words by separator `sep=NN`. |
joined_(*words, **sep) Joined words by separator `sep=" "`. |
len2(items) Make built-in function `len` work for generators, iterators, etc. |
map1(func, *xs) Apply each argument to a single-argument function and return a `tuple` of results. |
map2(func, *xs) Apply arguments to a function and return a `tuple` of results. |
property_doc_(doc) Decorator for a property with documentation. |
ub2str(ub) Convert `unicode` or `bytes` to `str`. |

Variables
| __all__ = `_ALL_LAZY.basics`

Function Details

### clips (bstr, limit=50, white=`'````'`) |
Clip a string to the given length limit. Arguments: `bstr` - String (`bytes` or `str`). `limit` - Length limit (`int`). `white` - Optionally, replace all whitespace (`str`). Returns: The clipped or unclipped `bstr`.

### halfs2 (str2) |
Split a string in 2 halfs. Arguments: `str2` - String to split (`str`). Returns: 2-Tuple (_1st, _2nd) half (`str`). Raises: `ValueError` - Zero or odd `len`(`str2`).

### isclass (obj) |
Return `True` if `obj` is a `class`. See Also: Python's `inspect.isclass`.

### isfinite (obj) |
Check for `Inf` and `NaN` values. Arguments: `obj` - Value (`scalar`). Returns: `False` if `obj` is `INF` or `NAN`, `True` otherwise. Raises: `TypeError` - Non-scalar `obj`.

### isint (obj, both=False) |
Check for `int` type or an integer `float` value. Arguments: `obj` - The object (any `type`). `both` - Optionally, check `float` type and value (`bool`). Returns: `True` if `obj` is `int` or an integer `float`, `False` otherwise.

### isneg0 (obj) |
Check for NEG0, negative 0.0. Arguments: `obj` - Value (`scalar`). Returns: `True` if `obj` is `NEG0` or -0.0, `False` otherwise.

### isscalar (obj) |
Check for scalar types. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is `scalar`, `False` otherwise.

### issequence (obj, *excluded) |
Check for sequence types. Arguments: `obj` - The object (any `type`). `excluded` - Optional exclusions (`type`). Returns: `True` if `obj` is a sequence, `False` otherwise. Note: Excluding `tuple` implies excluding `namedtuple`.

### isstr (obj) |
Check for string types. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is `str`, `False` otherwise.

### issubclassof (Sub, Super) |
Check whether a class is a sub-class of a super class. Arguments: `Sub` - The sub-class (`class`). `Super` - The super class (`class`). Returns: `True` if `Sub` is a sub-class of `Super`, `False` otherwise (`bool`).

### joined (*words, **sep) |
Joined words by separator `sep=NN`. Arguments: `words` - One, two or more words (`str`s). `sep` - Separator C({str}), default `NN`. Returns: Joined `words` C({str}).

### joined_ (*words, **sep) |
Joined words by separator `sep=" "`. Arguments: `words` - One, two or more words (`str`s). `sep` - Separator C({str}), default `" "`. Returns: Joined `words` C({str}).

### len2 (items) |
Make built-in function `len` work for generators, iterators, etc. since those can only be started exactly once. Arguments: `items` - Generator, iterator, list, range, tuple, etc. Returns: 2-Tuple `(n, items)` of the number of items (`int`) and the items (`list` or `tuple`).

### map1 (func, *xs) |
Apply each argument to a single-argument function and return a `tuple` of results. Arguments: `func` - Function to apply (`callable`). `xs` - Arguments to apply (`any positional`). Returns: Function results (`tuple`).

### map2 (func, *xs) |
Apply arguments to a function and return a `tuple` of results. Unlike Python 2's built-in `map`, Python 3+ `map` returns a `map` object, an iterator-like object which generates the results only once. Converting the `map` object to a tuple maintains Python 2 behavior. Arguments: `func` - Function to apply (`callable`). `xs` - Arguments to apply (`list, tuple, ...`). Returns: Function results (`tuple`).

### property_doc_ (doc) |
Decorator for a property with documentation. Arguments: `doc` - The property documentation (`str`). Example:
    >>> @property_doc_("documentation text.")
    >>> def name(self):
    >>>     ...
    >>>
    >>> @name.setter
    >>> def name(self, value):
    >>>     ...