Re: Conditionally subclassing based on Import

2008-10-03 Thread Gary Herron
David Pratt wrote: > 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 Somethin

Conditionally subclassing based on Import

2008-10-02 Thread David Pratt
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): -- http://mail.python.or