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 itr and zero to test for empty iterable’s and zeroed variables.

Returns True if a variable is None or '', returns False if variable passes the tests

Example 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 return True if the variable is int 0 or str '0'

  • itr – if itr=True, then return True if the variable is [], {}, or is an iterable and has 0 length

Return bool is_blank

True if a variable is blank (None, '', 0, [] etc.)

Return bool is_blank

False if a variable has content (or couldn’t be checked properly)