Package schrodinger :: Package utils :: Module moduleproxy :: Class ModuleProxy
[hide private]
[frames] | no frames]

Class ModuleProxy

object --+
         |
        ModuleProxy

A class to use as a placeholder for a non-essential module, raising an exception when something tries to use it.

Instance Methods [hide private]
 
__init__(self, name)
x.__init__(...) initializes x; see help(type(x)) for signature
 
__getattr__(self, attr)
Simply raise an exception any time something tries to make use of functionality from the fake module.
 
__nonzero__(self)
Always return False, indicating that the instance is not usable as a module.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name)
(Constructor)

 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

__nonzero__(self)
(Boolean test operator)

 

Always return False, indicating that the instance is not usable as a
module.

This allows for conditional behavior to be set up, based on a check
for a proxy module. For example:

    matplotlib = try_import("matplotlib")

    if matplotlib:
        create_pretty_graph()
    else:
        print_boring_numbers()