I like that. I usually end up doing that with ElementTree:try:from xml.etree import cElementTree as etree
except:try:from lxml import etreeexcept:from xml.etree import ElementTree as etreeIt would all be:import xml.etree.cElementTree or lxml.etree or xml.etree.ElementTree as etreeOn Thu, Dec 26, 2013 at 10:36 PM, Amber Yust <amber.yust@gmail.com> wrote:
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.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/--RyanWhen your hammer is C++, everything begins to look like a thumb.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/