empty¶
-
privex.helpers.common.empty(v, zero: bool = False, itr: bool = False) → bool[source]¶ Quickly check if a variable is empty or not. By default only ‘’ and None are checked, use
itrandzeroto test for empty iterable’s and zeroed variables.Returns
Trueif a variable isNoneor'', returnsFalseif variable passes the testsExample usage:
>>> x, y = [], None >>> if empty(y): ... print('Var y is None or a blank string') ... >>> if empty(x, itr=True): ... print('Var x is None, blank string, or an empty dict/list/iterable')
- Parameters
v – The variable to check if it’s empty
zero – if
zero=True, then returnTrueif the variable is int0or str'0'itr – if
itr=True, then returnTrueif the variable is[],{}, or is an iterable and has 0 length
- Return bool is_blank
Trueif a variable is blank (None,'',0,[]etc.)- Return bool is_blank
Falseif a variable has content (or couldn’t be checked properly)