Loading a class the name of which is only known runtime

Tim Gahnström /Bladerman tim at bladerman.com
Tue Apr 8 13:24:15 EDT 2003


"Mads Orbesen Troest" <mads at troest.NEVERMORE.dk
> Is it possible to load (import and instantiate) a class dynamically in
> Python? I have a feeling the answer is Yes, but as I am unfortunately not
> quite the python expert (yet :) forgive me if I ask something obvious.

If this is what ou are asking for it is certanly possible.

if test:
    import modul1
    a=class1()
else:
    import module2
    b=class2()

Good luck

Tim







More information about the Python-list mailing list