<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_omega_scan_config(channellist, fobj, header=True):
 """Write a `ChannelList` to an Omega-pipeline scan configuration file This method is dumb and assumes the channels are sorted in the right order already """

    if isinstance(fobj, FILE_LIKE):
        close = False
    else:
        fobj = open(fobj, 'w')
        close = True
    try:
        # print header
        if header:
            print('# Q Scan configuration file', file=fobj)
            print('# Generated with GWpy from a ChannelList', file=fobj)
        group = None
        for channel in channellist:
            # print header
            if channel.group != group:
                group = channel.group
                print('\n[%s]' % group, file=fobj)
            print("", file=fobj)
            print_omega_channel(channel, file=fobj)
    finally:
        if close:
            fobj.close()