<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def dump_part(part, total_segments=None):
 """ 'part' may be the hash_key if we are dumping just a few hash_keys - else it will be the segment number """

    try:
        connection = Connection(host=config['host'], region=config['region'])

        filename = ".".join([config['table_name'], str(part), "dump"])
        if config['compress']:
            opener = gzip.GzipFile
            filename += ".gz"
        else:
            opener = open

        dumper = BatchDumper(connection, config['table_name'], config['capacity'], part, total_segments)

        with opener(filename, 'w') as output:
            while dumper.has_items:
                items = dumper.get_items()

                for item in items:
                    output.write(json.dumps(item))
                    output.write("\n")
                output.flush()
                config['queue'].put(len(items))
        config['queue'].put('complete')
    except Exception as e:
        print('Unhandled exception: {0}'.format(e))