parameters: (self, key, value)
docstring: Set an attr with protection of class members.
  
          This calls :meth:`self.__setitem__` but convert :exc:`KeyError` to
          :exc:`AttributeError`.
  
          Examples
          --------
  
          >>> s = Struct()
          >>> s.a = 10
          >>> s.a
          10
          >>> try:
          ...     s.get = 10
          ... except AttributeError:
          ...     print("you can't set a class member")
          ...
          you can't set a class member
docstring_summary: Set an attr with protection of class members.
docstring_tokens: Set an attr with protection of class members .
function: def __setattr__(self, key, value):
          """Set an attr with protection of class members.
  
          This calls :meth:`self.__setitem__` but convert :exc:`KeyError` to
          :exc:`AttributeError`.
  
          Examples
          --------
  
          >>> s = Struct()
          >>> s.a = 10
          >>> s.a
          10
          >>> try:
          ...     s.get = 10
          ... except AttributeError:
          ...     print("you can't set a class member")
          ...
          you can't set a class member
          """
          # If key is an str it might be a class member or instance var
          if isinstance(key, str):
              # I can't simply call hasattr here because it calls getattr, which
              # calls self.__getattr__, which returns True for keys in
              # self._data.  But I only want keys in the class and in
              # self.__dict__
              if key in self.__dict__ or hasattr(Struct, key):
                  raise AttributeError(
                      'attr %s is a protected member of class Struct.' % key
                  )
          try:
              self.__setitem__(key, value)
          except KeyError as e:
              raise AttributeError(e)
function_tokens: def __setattr__ ( self , key , value ) : # If key is an str it might be a class member or instance var if isinstance ( key , str ) : # I can't simply call hasattr here because it calls getattr, which # calls self.__getattr__, which returns True for keys in # self._data.  But I only want keys in the class and in # self.__dict__ if key in self . __dict__ or hasattr ( Struct , key ) : raise AttributeError ( 'attr %s is a protected member of class Struct.' % key ) try : self . __setitem__ ( key , value ) except KeyError as e : raise AttributeError ( e )