'Set the value and/or comment and/or position of a specified keyword.
If the keyword does not already exist in the header, a new keyword is
created in the specified position, or appended to the end of the header
if no position is specified.
This method is similar to :meth:`Header.update` prior to PyFITS 3.1
/ Astropy v0.1.
.. note::
It should be noted that ``header.set(keyword, value)`` and
``header.set(keyword, value, comment)`` are equivalent to
``header[keyword] = value`` and
``header[keyword] = (value, comment)`` respectively.
New keywords can also be inserted relative to existing keywords
using, for example::
>>> header.insert(\'NAXIS1\', (\'NAXIS\', 2, \'Number of axes\'))
to insert before an existing keyword, or::
>>> header.insert(\'NAXIS\', (\'NAXIS1\', 4096), after=True)
to insert after an existing keyword.
The only advantage of using :meth:`Header.set` is that it
easily replaces the old usage of :meth:`Header.update` both
conceptually and in terms of function signature.
Parameters
keyword : str
A header keyword
value : str, optional
The value to set for the given keyword; if None the existing value
is kept, but \'\' may be used to set a blank value
comment : str, optional
The comment to set for the given keyword; if None the existing
comment is kept, but ``\'\'`` may be used to set a blank comment
before : str, int, optional
Name of the keyword, or index of the `Card` before which this card
should be located in the header.  The argument ``before`` takes
precedence over ``after`` if both specified.
after : str, int, optional
Name of the keyword, or index of the `Card` after which this card
should be located in the header.'

def set(self, keyword, value=None, comment=None, before=None, after=None):

    if ((len(keyword) <= KEYWORD_LENGTH) and Card._keywd_FSC_RE.match(keyword) and (keyword not in self._keyword_indices)):
        new_card = Card(keyword, value, comment)
        new_keyword = new_card.keyword
    else:
        new_keyword = keyword
    if ((new_keyword not in Card._commentary_keywords) and (new_keyword in self)):
        if (comment is None):
            comment = self.comments[keyword]
        if (value is None):
            value = self[keyword]
        self[keyword] = (value, comment)
        if ((before is not None) or (after is not None)):
            card = self._cards[self._cardindex(keyword)]
            self._relativeinsert(card, before=before, after=after, replace=True)
    elif ((before is not None) or (after is not None)):
        self._relativeinsert((keyword, value, comment), before=before, after=after)
    else:
        self[keyword] = (value, comment)
