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


Groups > comp.lang.python > #20169

Re: changing sys.path

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <andrea.crotti.0@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '"c"': 0.07; 'subject:changing': 0.07; 'manipulation': 0.09; 'namespace': 0.09; 'path.': 0.09; 'api': 0.09; 'exception': 0.12; 'declaration': 0.16; 'name)': 0.16; 'cc:addr:python-list': 0.16; 'this:': 0.16; 'wrote:': 0.18; 'appears': 0.19; 'cc:no real name:2**0': 0.21; 'maybe': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.26; 'code': 0.26; 'import': 0.27; 'fact': 0.27; "i'm": 0.28; 'cc:addr:python.org': 0.29; 'pm,': 0.29; "didn't": 0.30; 'message-id:@gmail.com': 0.31; 'actually': 0.31; 'does': 0.32; 'supposed': 0.32; 'changing': 0.32; 'received:209.85.212': 0.33; 'header:User-Agent:1': 0.33; 'instead': 0.33; 'agree': 0.33; 'extend': 0.36; 'received:10.0.0': 0.37; 'received:google.com': 0.37; 'either': 0.37; 'happens': 0.38; 'received:209.85': 0.38; 'goes': 0.39; 'received:209': 0.39; 'might': 0.40; 'more': 0.61; 'forward': 0.63; 'gathering': 0.67; 'definition:': 0.84; 'otten': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=tjnD1xF1fsKH2dx7XjXkKwAuIDbeZCZfcEgfMDokXno=; b=fsCVq04ob7Qkco/UF6Bf4iQQ7nsGFN6I1odfSwjKns/9+9JBQYdKHLxhETNAvcymC/ rkL6I/hUXLKA+Xxwzu7ar0vXGD5z0O21VcZF+ap14RthC+ljU43SRkpmjnR8BivlNtrG RC/oI9uf4grtkyiEmbws7UrEy6VRASRLZ0cDQ=
Date Fri, 10 Feb 2012 15:38:18 +0000
From Andrea Crotti <andrea.crotti.0@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111224 Thunderbird/9.0.1
MIME-Version 1.0
To Peter Otten <__peter__@web.de>
Subject Re: changing sys.path
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> <jh3d0m$s7k$1@dough.gmane.org>
In-Reply-To <jh3d0m$s7k$1@dough.gmane.org>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5666.1328888303.27778.python-list@python.org> (permalink)
Lines 37
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328888303 news.xs4all.nl 6906 [2001:888:2000:d::a6]:58053
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20169

Show key headers only | 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