Re: Handling file extensions and drivers


I hadn't thought of mime types at all. That would be perfect but as you say, not suitable because all the formats would need to be there.

I ended up writing a small dictionary of mappings between some popular driver names and possible file extensions (as decided by me):

driver_extensions = {
    "ESRI Shapefile": [".shp"],
    "GeoJSON": [".json", ".geojson"],
    "GPKG": [".gpkg"],
    "GML": [".gml", ".xml"],

Filtering the list of supported drivers to just those known ones can now be done with a fancy dict comprehension like:

drivers = {
    driver: modes
    for driver, modes in fiona.supported_drivers.items()
    if driver_extensions.get(driver)

And if needed a flat list of the extensions is a double list comprehension like:

extensions = [
    for sublist in extensions.values()
    for ext in sublist
-> `['.shp', '.json', '.geojson', '.gpkg', '.gml', '.xml']`

Join to automatically receive all group messages.