In fact, reuse of the 'or' keyword also leads to these nice options:
On Thu Dec 26 2013 at 7:40:19 PM, Bruce Leban <bruce@leapyear.org> wrote:I think you mean do the import if the name is unbound or bound to None. Otherwise, it doesn't work in the example you gave.Yes, that is what I meant, sorry. Another option would be "not bound to something that is not a module" - but I think "unbound or None" is probably the most versatile option.On Thu Dec 26 2013 at 8:08:45 PM, Steven D'Aprano <steve@pearwood.info> wrote:I'm not (yet) convinced of the need for this functionality, but if
Python did gain this, I think I would prefer the colour of this
bike-shed to be "perhaps import" rather than "maybe import".Another option would be to re-use the 'or' keyword:from foo import bar or NoneWhere the bit after the 'or' simply specifies a default value to assign if an ImportError occurs.