def write(self, outfile, filename='stdout', action='union'):
    assert (action in ('union', 'intersect'))
    op = (' + sum ' if (action == 'union') else ' * ')
    fw = must_open(filename, 'w')
    print('INPUT:', file=fw)
    ss = []
    pad = len(str(len(self.indices)))
    for (i, e) in enumerate(self.indices):
        s = 's{0:0{1}d}'.format((i + 1), pad)
        ss.append(s)
        print('{} = {}'.format(s, e.rsplit('.', 1)[0]), file=fw)
    print('OUTPUT:', file=fw)
    print('{} = {}'.format(outfile, op.join(ss)), file=fw)
    fw.close()
def write(self, outfile, filename='stdout', action='union'):
    assert (action in ('union', 'intersect'))
    op = (' + sum ' if (action == 'union') else ' * ')
    fw = must_open(filename, 'w')
    print('INPUT:', file=fw)
    ss = []
    pad = len(str(len(self.indices)))
    for (i, e) in enumerate(self.indices):
        s = 's{0:0{1}d}'.format((i + 1), pad)
        ss.append(s)
        print('{} = {}'.format(s, e.rsplit('.', 1)[0]), file=fw)
    print('OUTPUT:', file=fw)
    print('{} = {}'.format(outfile, op.join(ss)), file=fw)
    fw.close()