Absolute imports?

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Jan 10 05:13:38 EST 2011


Roy Smith wrote:
> [snip]
> It's reasonably straight-forward to figure out that absolute path, 
> starting from sys.argv[0] and using the tools in os.path.  Now I need to 
> import the file, given that I know its absolute pathname.  It looks like 
> imp.load_source() does what I want, I'm just wondering if there's a 
> cleaner way.
>   

What about

config = __import__(configPath.replace('.py', ''))


JM




More information about the Python-list mailing list