In python, what is contained in the info property of a module object?

I'm looking into creating a Plugin structure for a program and making it so even the core library is treated as plugins. in my research I came across this code that is dynamically importing modules.

def __initialize_def(self, module):
    """Attempt to load the definition"""

    # Import works the same for py files and package modules so strip!
    if module.endswith(".py"):
        name = module [:-3]
    else:
        name = module

    # Do the actual import
    __import__(name)
    definition = sys.modules[name]

    # Add the definition only if the class is available
    if hasattr(definition, definition.info["class"]):
        self.definitions[definition.info["name"]] = definition
        logging.info("Loaded %s" % name)

I have tried to understand what this code is doing and I've succeeded to a point. However, I simply can't understand the latter part of the code, specifically these two lines:

if hasattr(definition, definition.info["class"]):
    self.definitions[definition.info["name"]] = definition

I can't figure out what definition.info["<key>"] is referring to.

What is this .info[] dictionary and what does it hold? Is it common to all Python objects or only module objects? What is it useful for?

Answers


py> import sys,os
py> sys.modules["os"].info["class"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'info'

So this info attribute must be specific to modules that can be used as plugins in this program.


Need Your Help

Optimize NHibernate: Load all data from specified tables

nhibernate caching optimization fluent-nhibernate prefetch

Scenario: I have built an ASP.NET MVC application that manages my cooking recipes. I am using FluentNHibernate to access data from the following tables:

Android: Box that fills entire screen with content below

java android xml android-layout android-fragments

I've been trying to figure out how to place a container that fills the entire screen vertically inside a ScrollView that has content below.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.