Conditionally subclassing based on Import

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Pratt

    Conditionally subclassing based on Import

    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(MyBas e):

Working...