'Returns a string representation of the header.
By default this uses no separator between cards, adds the END card, and
pads the string with spaces to the next multiple of 2880 bytes.  That
is, it returns the header exactly as it would appear in a FITS file.
Parameters
sep : str, optional
The character or string with which to separate cards.  By default
there is no separator, but one could use ``\'\\n\'``, for example, to
separate each card with a new line
endcard : bool, optional
If True (default) adds the END card to the end of the header
string
padding : bool, optional
If True (default) pads the string with spaces out to the next
multiple of 2880 characters
Returns
s : str
A string representing a FITS header.'

def tostring(self, sep='', endcard=True, padding=True):

    lines = []
    for card in self._cards:
        s = str(card)
        while s:
            lines.append(s[:Card.length])
            s = s[Card.length:]
    s = sep.join(lines)
    if endcard:
        s += (sep + _pad('END'))
    if padding:
        s += ('    ' * _pad_length(len(s)))
    return s
