human_name

privex.helpers.common.human_name(class_name: Union[str, bytes, callable, Type[object]])str[source]

This function converts a class/function name into a Title Case name. It also directly accepts classes/functions.

Input names can be either snake case my_function, or InitialCaps MyClass - though mixtures of the two may work, such as some_functionName - however some_FunctionName will not (causes double spaces).

Examples

Using a plain string or bytes:

>>> human_name(b'_some_functionName')
'Some Function Name'
>>> human_name('SomeClassName')
'Some Class Name'

Using a reference to a function:

>>> def some_func():
...     pass
>>> human_name(some_func)
'Some Func'

Using a reference to a class, or an instance of a class:

>>> class MyExampleClass:
...     pass
>>> my_instance = MyExampleClass()
>>> human_name(MyExampleClass)
'My Example Class'
>>> human_name(my_instance)
'My Example Class'
Parameters

class_name – The name of a class/function specified either in InitialCaps or snake_case. You may also pass a function reference, class reference, or class instance. (see examples)

Return str human_name

The humanised Title Case name of class_name