[Python-ideas] "maybe import"?
Amber Yust
amber.yust at gmail.com
Fri Dec 27 05:38:29 CET 2013
In fact, reuse of the 'or' keyword also leads to these nice options:
import foo or None as bar
from foo import bar or None as baz
On Thu Dec 26 2013 at 8:36:24 PM, Amber Yust <amber.yust at gmail.com> wrote:
> On Thu Dec 26 2013 at 7:40:19 PM, Bruce Leban <bruce at 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 at 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 None
>
> Where the bit after the 'or' simply specifies a default value to assign if
> an ImportError occurs.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131227/b0e9d18d/attachment.html>
More information about the Python-ideas
mailing list