A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-November/094366.html below:

[Python-Dev] PEP 391 ready for review

[Python-Dev] PEP 391 ready for review [Python-Dev] PEP 391 ready for reviewNick Coghlan ncoghlan at gmail.com
Thu Nov 26 12:28:49 CET 2009
Terry Reedy wrote:
> if not hasattr(factory, '__call__'): factory = __import__(factory)

That won't quite work since the string generally isn't referring to a
module, and due to the quirk of __import__ returning the top level
module since that is what the interpreter needs to bind to a name as
part of a normal import statement.

This would need to look more like:

if not hasattr(factory, '__call__'):
  mod_name, dot, attr = factory.rpartition('.')
  if not dot:
    raise ValueError("<something meaningful>")
  module = imputil.import_module(mod_name)
  factory = getattr(module, attr)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4