Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20169

Re: changing sys.path

Date 2012-02-10 15:38 +0000
From Andrea Crotti <andrea.crotti.0@gmail.com>
Subject Re: changing sys.path
References (1 earlier) <d0253e03-fed0-40db-8a7a-e9195ce92889@k28g2000yqc.googlegroups.com> <4F3516CC.1070401@gmail.com> <4F3528B2.3050806@davea.name> <4F352EE8.1030101@gmail.com> <jh3d0m$s7k$1@dough.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.5666.1328888303.27778.python-list@python.org> (permalink)

Show all headers | View raw


On 02/10/2012 03:27 PM, Peter Otten wrote:
> 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. 


I would agree if I didn't have this declaration
__import__('pkg_resources').declare_namespace(__name__)
in each subdirectory.

And how do you explain the fact that changing the order everything works?
Namespace packages are supposed to work exactly like this, if it doesn't 
resolve the
"c" instead of raising an Exception it goes forward in the sys.path and 
try again, which
is what actually happens when I do this

sys.path.append(path.abspath('ab'))
sys.path.append(path.abspath('ac'))

from a.b import api as api_ab
from a.c import api as api_ac

Maybe this:
Definition: pkgutil.extend_path(path, name)
Docstring:
Extend a package's path.

Intended use is to place the following code in a package's __init__.py:

     from pkgutil import extend_path
     __path__ = extend_path(__path__, __name__)


might come handy, from what I'm gathering is the only way to have a more 
dynamic path
manipulation with namespace packages..

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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