code: def is_unit(q):
      '''
      is_unit(q) yields True if q is a pint unit or a string that names a pint unit and False
        otherwise.
      '''
      if isinstance(q, six.string_types):
          try: return hasattr(units, q)
          except: return False
      else:
          cls = type(q)
          return cls.__module__.startswith('pint.') and cls.__name__ == 'Unitf is_unit(q):
      '''
      is_unit(q) yields True if q is a pint unit or a string that names a pint unit and False
        otherwise.
      '''
      if isinstance(q, six.string_types):
          try: return hasattr(units, q)
          except: return False
      else:
          cls = type(q)
          return cls.__module__.startswith('pint.') and cls.__name__ == 'Unit'
docs: is_unit(q) yields True if q is a pint unit or a string that names a pint unit and False
        otherwise.