PYTHON 117
Misc_util.py By cbettis on 31st March 2022 06:10:01 PM
  1. """Miscellaneous utility methods with minimal dependencies.
  2.  
  3. by Carl Bettis"""
  4.  
  5. def if_null(thing, default_value):
  6.     """If thing == None then return default_value, else return thing"""
  7.     if thing == None:
  8.         thing = default_value
  9.     return thing
  10.  
  11. def if_null_or_empty(text, default_text):
  12.     """If text == None or len(text) == 0 then return default_text, else return text"""
  13.     if text == None or len(text) == 0:
  14.         text = default_text
  15.     return text
  16.  
  17. def if_null_or_whitespace(text, default_text):
  18.     """If text == None or len(text) == 0 or text.isspace() then return default_text, else return text"""
  19.     if text == None or len(text) == 0 or text.isspace():
  20.         text = default_text
  21.     return text
  22.  
  23. def if_value(value_to_test, default_value, test_value=None):
  24.     """If value_to_test == test_value then return default_value, else return value_to_text"""
  25.     if value_to_test == test_value:
  26.         value_to_test = default_value
  27.     return value_to_test

Caracabe Heap is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.