EGA-archive / beacon2-ri-api

Beacon v2 Reference Implementation (API)
Apache License 2.0
16 stars 38 forks source link

import plugins as db #195

Open alabarga opened 1 year ago

alabarga commented 1 year ago

import different backends with same alias

https://stackoverflow.com/questions/72106437/dynamically-assigning-module-names-as-aliases

import importlib
module_names = [('math',), ('numpy','np')]

def Importer(m_name):
    module = importlib.import_module(m_name[0])
    if len(m_name) > 1:
        globals()[x[1]] = module

for x in module_names:
    Importer(x)
names = getattr(foo, '__all__', [])
if not names:
  names = [n for n in foo.__dict__.keys() if n[:1] != '_']

for name in names:
  globals()[name] = getattr(foo, name)