Is possible to auto-import a module from a diferent subfolder in other subfolder?
        Posted  
        
            by mamcx
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by mamcx
        
        
        
        Published on 2010-05-10T16:55:21Z
        Indexed on 
            2010/05/10
            17:14 UTC
        
        
        Read the original article
        Hit count: 396
        
I have a kind of plugin system, with this layout:
- Python
-- SDK
-- Plugins
---- Plugin1
---- Plugin2
All 3 have a __init__.py file. I wonder if is possible to be able to do import SDK from any plugin (as if SDK was in the site-packages folder).
I'm in a situation where need to deploy, update, delete, add or change SDK files or any of the plugins under non-admin accounts, and wonder if I can get SDK in a clean way (I could sys.path.append in all plugins but I wonder if exist a better option).
I imagine that using this in the Plugins init coulkd work:
import sys
import os
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))
print ROOT_DIR
sys.path.append( ROOT_DIR )
But clearly is not executed this code (I imagine init was auto-magicalled executed in the load of the module :( )
© Stack Overflow or respective owner