[CentralOH] Dynamic Importing

John Santiago jdsantiagojr at gmail.com
Fri Mar 15 05:41:48 CET 2013


I didn't know about import_module. Thank You!


On Fri, Mar 15, 2013 at 12:24 AM, John Santiago <jdsantiagojr at gmail.com>wrote:

> Man that worked great! Thank you!
>
> here is revised ::
> blueprints = ['frontend', 'admin']
> for module in blueprints:
>     mod = import_module('controllers.%s' % module)
>     app.register_blueprint(mod.mod)
>
>
> On Thu, Mar 14, 2013 at 10:26 PM, <jep200404 at columbus.rr.com> wrote:
>
>> On Thu, 14 Mar 2013 21:37:10 -0400, John Santiago <jdsantiagojr at gmail.com>
>> wrote:
>>
>> > ... __import__('controllers.%s' % path, fromlist=[path])
>>
>> That __ stuff gives me the creeps.
>> Does importlib.import_module() work for you?
>>
>> test at test:~$ python
>> Python 2.7.3 (default, Sep 26 2012, 21:53:58)
>> [GCC 4.7.2] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> help(__import__)
>>
>> Help on built-in function __import__ in module __builtin__:
>>
>> __import__(...)
>>     __import__(name, globals={}, locals={}, fromlist=[], level=-1) ->
>> module
>>
>>     Import a module. Because this function is meant for use by the Python
>>     interpreter and not for general use it is better to use
>>     importlib.import_module() to programmatically import a module.
>>
>> ...
>>
>> >>> help(importlib.import_module)
>>
>> Help on function import_module in module importlib:
>>
>> import_module(name, package=None)
>>     Import a module.
>>
>>     The 'package' argument is required when performing a relative import.
>> It
>>     specifies the package to use as the anchor point from which to
>> resolve the
>>     relative import to an absolute import.
>>
>>
>> _______________________________________________
>> CentralOH mailing list
>> CentralOH at python.org
>> http://mail.python.org/mailman/listinfo/centraloh
>>
>
>
>
> --
> This electronic message is intended to be for the use only of the named
> recipient, and may contain information that is confidential or privileged.
> If you are not the intended recipient, you are hereby notified that any
> disclosure, copying, distribution or use of the contents of this message is
> strictly prohibited.  If you have received this message in error or are not
> the named recipient, please notify us immediately by contacting the sender
> at the electronic mail address noted above, and delete and destroy all
> copies of this message.  Thank you.
>



-- 
This electronic message is intended to be for the use only of the named
recipient, and may contain information that is confidential or privileged.
If you are not the intended recipient, you are hereby notified that any
disclosure, copying, distribution or use of the contents of this message is
strictly prohibited.  If you have received this message in error or are not
the named recipient, please notify us immediately by contacting the sender
at the electronic mail address noted above, and delete and destroy all
copies of this message.  Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/centraloh/attachments/20130315/2bb48f6d/attachment-0001.html>


More information about the CentralOH mailing list