'configuration for fileoutput:
fh=<existing open file handle>
file=filename to write to
mode=mode to open file as, default \'w\''

def __init__(self, *args, **kw):

    Output.__init__(self, *args, **kw)
    f = None
    if ('fh' in kw):
        self.fh = kw['fh']
        return
    elif ('file' in kw):
        f = kw['file']
    elif args:
        f = args[0]
    if f:
        if ('mode' in kw):
            mode = kw['mode']
        else:
            mode = 'w'
        if (mode == 'noclobber'):
            mode = 'w'
            try:
                while os.stat(f):
                    p = f.split('-')
                    try:
                        (p, n) = (p[:(-1)], int(p[(-1)]))
                    except ValueError:
                        n = 0
                    f = '-'.join((p + [('%04d' % (int(n) + 1))]))
            except OSError:
                pass
        self.fh = open(f, mode)
    else:
        self.fh = sys.stdout
