[Tutor] temporarily modifying sys.path

Tim Johnson tim at johnsons-web.com
Sun Nov 28 19:36:36 CET 2010


* Evert Rol <evert.rol at gmail.com> [101128 07:56]:
> > I need a function that will import a module (using __import__) from
> > only one specific location on my filesystem. Name collisions are
> > possible. To avoid this I could *temporarily* modify sys.path for
> > the operation so that it contains only the path that I want
> > to work from.
 
> Just curious, but could the imp module help you? imp.find_module
> appears to look on a specific path if you specify it, and it seems
> you have the path available here. From there imp.load_module
> perhaps.  I have very little experience with imp, but I'm
> wondering if it could help you without the necessity of modifying
> sys.path.
 
> Though I do think you can temporarily make a copy of sys.path,
> then modify sys.path, then after the import reassign sys.path to
> your temp variable. But try the above route first.
  I'll be darned. I never even heard of that module, but I just
  did an import and looked at the docs. I *will* give that a try.
  Thanks for the tip!
  cheers
-- 
Tim 
tim at johnsons-web.com or akwebsoft.com
http://www.akwebsoft.com


More information about the Tutor mailing list