add_folder_backslash

utilipy.decorators.add_folder_backslash(function=None, *, arguments: List[Union[str, int]] = [], _doc_style='numpy', _doc_fmt={})[source]

Add backslashes to str arguments.

For use in ensuring directory file-paths end in ‘/’, when os.join just won’t do.

Parameters
functionT.Callable or None, optional

the function to be decoratored if None, then returns decorator to apply.

argumentslist of string or int, optional

arguments to which to append ‘/’, if not already present strings are names of arguments. Can also be int, which only applies to args.

Returns
wrapperT.Callable

wrapper for function does a few things includes the original function in a method .__wrapped__

Other Parameters
_doc_style: str or formatter, optional

default ‘numpy’ parameter to wraps

_doc_fmt: dict, optional

default None parameter to wraps

Examples

For modifying a single argument

>>> @add_folder_backslash(arguments='path')
... def func(path):
...     return path
>>> func("~/Documents")
'~/Documents/'

When several arguments need modification.

>>> @add_folder_backslash(arguments=('path1', 'path2'))
... def func(path1, path2):
...     return (path1, path2)
>>> func("~/Documents", "~Desktop")
('~/Documents/', '~Desktop/')