Next / Previous / Contents / TCC Help System / NM Tech homepage

14.12. Element.__setitem__()

This method allows you to store attributes in an element as if it were a dictionary. For example, if you have an Element object called e and you want to an attribute align='center', this would do it:

e["align"] = "center"

Here's the actual method:

xml4create.py
# - - -   E l e m e n t . _ _ s e t i t e m _ _   - - -

    def __setitem__ ( self, key, value ):
        """Add an attribute to self.
          [ key is an attribute name as a string ->
              if key has namespace prefix not defined in
              self.doc.nsMap ->
                raise KeyError
              else ->
                self  :=  self with its attribute (key), minus
                    any trailing underbar if present, set to (value) ]
        """
        self.__setAttr ( key, value )