Correctness: sys.path.append("..")

Oleg Broytmann phd at phd.pp.ru
Tue Jan 8 17:09:59 EST 2002


On Tue, Jan 08, 2002 at 10:01:04PM +0000, Jeremy Bowers wrote:
> import sys
> if ".." not in sys.path:
> 	sys.path.append("..")
> 
> I know it works on Windows and Linux, for the last few versions of Python.
> Is there any thing wrong with this? It makes me vaguely nervous.

   There is nothing wrong, until you chnge current directory. Then this
sys.path entry will be applied to  different directory.
   Better, convert the path to n bsolute on using module "os" if it is
available:

import sys, os
parent_dir = os.path.abspath("..")
sys.path.append(parent_dir)

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.




More information about the Python-list mailing list