changing sys.path
Andrea Crotti
andrea.crotti.0 at gmail.com
Fri Feb 10 10:14:23 EST 2012
On 02/10/2012 03:06 PM, Dave Angel wrote:
>
> Yes, you've got periods in your directory names. A period means
> something special within python, and specifically within the import.
>
> When you say from a.c import api
>
> You're telling it: from package a get module c, and from there
> impoort the symbol api
>
> But package a has no module c, so it complains.
>
>
> In an earlier message you asserted you were using all absolute paths
> in your additions to sys.path. Here you're inserting relative ones.
> How come?
>
Well yes I have periods, but that's also the real-world situation.
We have many directories that are contributing to the same namespace in
the same superdirectory
which should not interfere, so it was decided to give this naming.
It would be quite hard to change I guess and I have to prove that this
is problem.
I renamed everything and this
import sys
from os import path
sys.path.insert(0, path.abspath('ab'))
from a.b import api as api_ab
sys.path.insert(0, path.abspath('ac'))
from a.c import api as api_ac
still fails, so the period in the name is not the problem.
Also absolute or relative paths in this small example doesn't make any
difference.
Adding all the paths in one go works perfectly fine anyway, so I
probably have to make sure
I add them *all* before anything is imported.
If there are better solutions I would like to hear them :)
More information about the Python-list
mailing list