Accept a list of alternative names in ffi.dlopen()

Issue #54 wontfix
Simon Sapin
created an issue

So, ffi.dlopen('cairo') opens on Linux and ffi.dlopen('libcairo-2') opens libcairo-2.dll on Windows, but I haven’t found a name that works on both. I’ll add something like this to cairocffi:

def dlopen(names):
    for name in names:
            return ffi.dlopen(name)
        except OSError:
    ffi.dlopen(names[0])  # Trigger the exception again

cairo = dlopen(['cairo', 'libcairo-2'])  # Maybe add variants for other platforms

It would be nice if ffi.dlopen() could accept a list and do this itself.

Comments (2)

  1. Armin Rigo

    You can also do

    ffi.dlopen('libcairo-2' if sys.platform == 'win32' else 'cairo')

    which seems short enough not to warrant this list-of-variants version.

  2. Log in to comment