Helper Module
- class kwhelp.helper.Formatter[source]
String Fromat Methods
- static get_formated_names(names: List[str], **kwargs) str [source]
Gets a formated string of a list of names
- Parameters
names (List[str]) – List of names
- Keyword Arguments
conj (str, optional) – Conjunction used to join list. Default
and
.wrapper (str, optional) – String to prepend and append to each value. Default
'
.
- Returns
formated such as
'final' and 'end'
or'one', 'final', and 'end'
- Return type
str
- static get_formated_types(types: Iterator[type], **kwargs) str [source]
Gets a formated string from a list of types.
- Parameters
types (Iterator[type]) – Types to create fromated string.
- Keyword Arguments
conj (str, optional) – Conjunction used to join list. Default
and
.wrapper (str, optional) – String to prepend and append to each value. Default
'
.
- Returns
Formated String
- Return type
str
- static get_missing_args_error_msg(missing_names: List[str], name: Optional[str] = '')[source]
Get an error message for a list of names.
- Parameters
missing_names (List[str]) – List of names that generated the error. Such as a list of missing arguments of a function.
name (Optional[str], optional) – Function, class, method name. Defaults to “”.
- Returns
Formated string for
missing_names
has elements; Otherwise, empty string is returned.- Return type
[type]
- static get_ordinal(num: int) str [source]
Returns the ordinal number of a given integer, as a string.
- Parameters
num (int) – integer to get ordinal value of.
- Returns
num as ordinal str. eg. 1 -> 1st, 2 -> 2nd, 3 -> 3rd, etc.
- Return type
str
- kwhelp.helper.is_iterable(arg: object, excluded_types: Iterable[type] = (<class 'str'>, )) bool [source]
Gets if
arg
is iterable.- Parameters
arg (object) – object to test
excluded_types (Iterable[type], optional) – Iterable of type to exlcude. If
arg
matches any type inexcluded_types
thenFalse
will be returned. Default(str,)
- Returns
True
ifarg
is an iterable object and not of a type inexcluded_types
; Otherwise,False
.- Return type
bool
Note
if
arg
is of type str then return result isFalse
.Example
# non-string iterables assert is_iterable(arg=("f", "f")) # tuple assert is_iterable(arg=["f", "f"]) # list assert is_iterable(arg=iter("ff")) # iterator assert is_iterable(arg=range(44)) # generator assert is_iterable(arg=b"ff") # bytes (Python 2 calls this a string) # strings or non-iterables assert not is_iterable(arg=u"ff") # string assert not is_iterable(arg=44) # integer assert not is_iterable(arg=is_iterable) # function # excluded_types, optionally exlcude types from enum import Enum, auto class Color(Enum): RED = auto() GREEN = auto() BLUE = auto() assert is_iterable(arg=Color) # Enum assert not is_iterable(arg=Color, excluded_types=(Enum, str)) # Enum
- kwhelp.helper.NO_THING = <kwhelp.helper.NoThing object>
Singleton Class instance that represents null object.