Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.01; 'sys': 0.05; 'importerror:': 0.07; 'names.': 0.07; 'paths': 0.07; 'subject:changing': 0.07; 'namespace': 0.09; 'api': 0.09; 'am,': 0.12; '(where': 0.15; '153': 0.16; '4096': 0.16; 'additions': 0.16; 'behaviour,': 0.16; 'come?': 0.16; 'package).': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; '(most': 0.21; 'cc:no real name:2**0': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'earlier': 0.23; 'ones.': 0.23; 'traceback': 0.24; 'module': 0.26; 'skip:[ 10': 0.27; 'import': 0.27; 'tried': 0.27; 'cc:addr:gmail.com': 0.28; 'example': 0.29; 'cc:addr:python.org': 0.29; 'specifically': 0.30; 'there': 0.33; 'header:User-Agent:1': 0.33; 'named': 0.33; 'file': 0.34; 'last):': 0.34; 'symbol': 0.34; 'something': 0.35; 'cc:2**1': 0.36; 'created': 0.37; 'but': 0.37; 'using': 0.37; 'received:192': 0.38; 'some': 0.38; 'getting': 0.38; 'absolute': 0.39; 'missing': 0.40; "you've": 0.61; 'total': 0.61; 'your': 0.61; 'here': 0.64; 'special': 0.66; 'header:Reply-To:1': 0.70; 'reply-to:no real name:2**0': 0.72; '14:36': 0.84; '14:46': 0.84; '14:47': 0.84; 'andrea': 0.84; 'python2': 0.84; 'order:': 0.91 Date: Fri, 10 Feb 2012 10:06:28 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111109 Thunderbird/3.1.16 MIME-Version: 1.0 To: Andrea Crotti Subject: Re: changing sys.path References: <4F3516CC.1070401@gmail.com> <4F3528B2.3050806@davea.name> <4F352EE8.1030101@gmail.com> In-Reply-To: <4F352EE8.1030101@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:XTQo+JnNdlEhIV6VNyHxqKfnTK8pwI4FW5Jcph1fNcn P4SbmbrrumBnRC+hHHdaCLBdBlN7uGrsHjRvZVS6jK5gH+WvYa fmSxKz3jaudYxUKosz0M91JFLiqiMvJYPbz563WN2VYef+rh1U gk499lI5VSjldFaepgA2IXSLC1PjlA1d/Cbqb9TFqfPKsC1Gbx RHWXMHtmLRQwGcaWMsCEspHfbsKHidTFcVo2OpkVGdBDOlColz PL4Bv004UMZB2SMp7hG2PhJRsygeIuOS2AKSbjQxtkLIaVgH8X 7qKThSVp0LDP53WwyhcbB5sNqgTP1/ekZyNyWHtX6CRJS6rPNc 4Igg+u2/+G/xCtOfrxtY= Cc: python-list@python.org, Rick Johnson X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 92 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328886399 news.xs4all.nl 6905 [2001:888:2000:d::a6]:50428 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:20166 On 02/10/2012 09:51 AM, Andrea Crotti wrote: > Ok now it's getting really confusing, I tried a small example to see > what is the real behaviour, > so I created some package namespaces (where the __init__.py declare the > namespace package). > > /home/andrea/test_ns: > total used in directory 12 available 5655372 > drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:46 a.b > drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:46 a.c > -rw-r--r-- 1 andrea andrea 125 Feb 10 14:46 test.py > > /home/andrea/test_ns/a.b: > total 8 > drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:47 a > -rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py > > /home/andrea/test_ns/a.b/a: > total 8 > drwxr-xr-x 2 andrea andrea 4096 Feb 10 14:47 b > -rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py > > /home/andrea/test_ns/a.b/a/b: > total 12 > -rw-r--r-- 1 andrea andrea 25 Feb 10 14:36 api.py > -rw-r--r-- 1 andrea andrea 153 Feb 10 14:37 api.pyc > -rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py > > /home/andrea/test_ns/a.c: > total 8 > drwxr-xr-x 3 andrea andrea 4096 Feb 10 14:47 a > -rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py > > /home/andrea/test_ns/a.c/a: > total 8 > drwxr-xr-x 2 andrea andrea 4096 Feb 10 14:47 c > -rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py > > /home/andrea/test_ns/a.c/a/c: > total 12 > -rw-r--r-- 1 andrea andrea 20 Feb 10 14:36 api.py > -rw-r--r-- 1 andrea andrea 148 Feb 10 14:38 api.pyc > -rw-r--r-- 1 andrea andrea 56 Feb 10 14:35 __init__.py > > > So this test.py works perfectly: > import sys > sys.path.insert(0, 'a.c') > sys.path.insert(0, 'a.b') > > from a.b import api as api_ab > > from a.c import api as api_ac > > While just mixing the order: > import sys > sys.path.insert(0, 'a.b') > > from a.b import api as api_ab > > sys.path.insert(0, 'a.c') > from a.c import api as api_ac > > Doesn't work anymore > > [andrea@precision test_ns]$ python2 test.py > Traceback (most recent call last): > File "test.py", line 7, in > from a.c import api as api_ac > ImportError: No module named c > > > > Am I missing something/doing something stupid? 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? -- DaveA