'Save palette to text file.
.. warning:: This method is experimental.'

def save(self, fp):

    if self.rawmode:
        raise ValueError('palette    contains    raw    palette    data')
    if isinstance(fp, str):
        fp = open(fp, 'w')
    fp.write('#    Palette\n')
    fp.write(('#    Mode:    %s\n' % self.mode))
    for i in range(256):
        fp.write(('%d' % i))
        for j in range((i * len(self.mode)), ((i + 1) * len(self.mode))):
            try:
                fp.write(('    %d' % self.palette[j]))
            except IndexError:
                fp.write('    0')
        fp.write('\n')
    fp.close()
