Conditionally subclassing based on Import

David Pratt fairwinds.dp at gmail.com
Fri Oct 3 08:45:19 CEST 2008


Hi, just want to conditionally base a class on another if it can be  
imported,  otherwise base it on object. Does the following look ok   
for this?

try:
      import foo.bar
except ImportError:
     MyBase = foo.bar.Baz
else:
     MyBase = object

class Something(MyBase):




More information about the Python-list mailing list