On Wed, 20 May 2009 22:01:50 +0200 Jean-Michel Pichavant <[email protected]> wrote:
> You are right, but my concern is not the relative path resolution. Let
> me clarify:
>
> /home/jeanmichel/test.py:
> "import sys
> print sys.path"
>
> >python.exe test.py
> sys.path = ['/home/jeanmichel']
> > from within a python shell:
> sys.path = ['']
>
> The unpredictable effect of '' (at least something I did not predict) is
> that it allows absolute path resolution, while '/home/jeanmichel' cannot.
> Example :
> write a anotherTest.py file:
> "
> __import__('/home/jeanmichel/test')
> "
It works for me with py2.6, what version do you have?
> anotherTest.py will be successfully imported in a python shell ('' +
> '/home/jeanmichel/test.py' is a valid path), but the "python.exe
> anotherTest2.py" form will fail as it will try for '/home/jeanmichel'
> +'/home/jeanmichel/test.py' which is not a valid path.
I believe python uses os.path.join algorithm to combine paths which
discards anything (absolute or not) if absolute path gets appended to
it:
os.path.join('/some/path', '/home/jeanmichel') == '/home/jeanmichel'
> So my question is: "why the shell is adding '' when the interpreter is
> adding the full path ?"
Looks like a solid way to construct relative imports to me.
--
Mike Kazantsev // fraggod.net
signature.asc
Description: PGP signature
-- http://mail.python.org/mailman/listinfo/python-list
