def get_field(field_name, shapefile, case_sensitive = True):
    """Return the field in shapefile that corresponds to field_name,
        None otherwise.

        Inputs:
            - field_name: string to look for.
            - shapefile: where to look for the field.
            - case_sensitive: indicates whether the case is relevant when
            comparing field names

        Output:
            - the field name in the shapefile that corresponds to field_name,
            None otherwise."""
    layer_count = shapefile.GetLayerCount()
    for l in range(layer_count):
        layer = shapefile.GetLayer(l)
        feature_count = layer.GetFeatureCount()
        assert feature_count > 0
        feature = layer.GetFeature(0)
        field_count = feature.GetFieldCount()
        for f in range(field_count):
            field_defn = feature.GetFieldDefnRef(f)
            if case_sensitive:
                if field_defn.GetNameRef() == field_name:
                    return field_defn.GetNameRef()
            # if not case sensitive, convert everything to lower case
            else:
                if field_defn.GetNameRef().lower() == field_name.lower():
                    return field_defn.GetNameRef()
    return None