Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #20168
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: changing sys.path |
| Date | 2012-02-10 16:27 +0100 |
| Organization | None |
| References | <mailman.5303.1328112912.27778.python-list@python.org> <d0253e03-fed0-40db-8a7a-e9195ce92889@k28g2000yqc.googlegroups.com> <4F3516CC.1070401@gmail.com> <4F3528B2.3050806@davea.name> <4F352EE8.1030101@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5665.1328887657.27778.python-list@python.org> (permalink) |
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 <module> > from a.c import api as api_ac > ImportError: No module named c > > > > Am I missing something/doing something stupid? The package a will be either a.c/a/ or a.b/a/ depending on whether a.c/ or a.b/ appears first in sys.path. If it's a.c/a, that does not contain a c submodule or subpackage.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
changing sys.path Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-01 16:15 +0000
Re: changing sys.path jmfauth <wxjmfauth@gmail.com> - 2012-02-01 09:06 -0800
Re: changing sys.path Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-01 09:17 -0800
Re: changing sys.path Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-10 13:08 +0000
Re: changing sys.path Dave Angel <d@davea.name> - 2012-02-10 09:24 -0500
Re: changing sys.path Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-10 14:51 +0000
Re: changing sys.path Dave Angel <d@davea.name> - 2012-02-10 10:06 -0500
Re: changing sys.path Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-10 15:14 +0000
Re: changing sys.path Peter Otten <__peter__@web.de> - 2012-02-10 16:27 +0100
Re: changing sys.path Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-10 15:38 +0000
Re: changing sys.path Peter Otten <__peter__@web.de> - 2012-02-10 16:40 +0100
Re: changing sys.path Peter Otten <__peter__@web.de> - 2012-02-10 17:00 +0100
Re: changing sys.path Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-02-10 20:58 +0000
Re: changing sys.path Tim Roberts <timr@probo.com> - 2012-02-02 21:10 -0800
Re: changing sys.path John Nagle <nagle@animats.com> - 2012-02-08 13:43 -0800
csiph-web