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


Groups > comp.lang.python > #109099

Re: Question about imports and packages

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Terry Reedy <tjreedy@udel.edu>
Newsgroups comp.lang.python
Subject Re: Question about imports and packages
Date Tue, 24 May 2016 23:36:37 -0400
Lines 24
Message-ID <mailman.76.1464147419.20402.python-list@python.org> (permalink)
References <CAPxRSnYXQL-0zTo81_QmhXan6nJ-fzCBpS6y5DjqS952SV=yjg@mail.gmail.com> <mailman.70.1464132967.20402.python-list@python.org> <5744f9b1$0$1603$c3e8da3$5496439d@news.astraweb.com> <ni36k9$5sr$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de PKjZOZwc/UKhzMtHTkGm/AbFYbCo+DUgs4JyM6IlaIPQ==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Question': 0.05; 'correct.': 0.07; '"python"': 0.09; 'imported': 0.09; 'imports': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python.': 0.11; 'jan': 0.11; 'wed,': 0.15; 'importing': 0.15; '+--': 0.16; '2016': 0.16; '__init__.py': 0.16; 'modules,': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'wrote:': 0.16; 'directory.': 0.18; 'runs': 0.18; 'extension': 0.20; 'work,': 0.21; 'setup,': 0.22; 'file.': 0.22; 'am,': 0.23; 'absolute': 0.23; 'import': 0.24; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; "skip:' 10": 0.28; 'class': 0.33; "d'aprano": 0.33; 'particular,': 0.33; 'steven': 0.33; 'similar': 0.33; 'file': 0.34; 'except': 0.34; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'files': 0.38; 'to:addr:python.org': 0.40; 'your': 0.60; 'received:96': 0.63; 'within': 0.64; '9:02': 0.84; 'received:fios.verizon.net': 0.91
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host pool-96-227-207-81.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0
In-Reply-To <5744f9b1$0$1603$c3e8da3$5496439d@news.astraweb.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <ni36k9$5sr$1@ger.gmane.org>
X-Mailman-Original-References <CAPxRSnYXQL-0zTo81_QmhXan6nJ-fzCBpS6y5DjqS952SV=yjg@mail.gmail.com> <mailman.70.1464132967.20402.python-list@python.org> <5744f9b1$0$1603$c3e8da3$5496439d@news.astraweb.com>
Xref csiph.com comp.lang.python:109099

Show key headers only | View raw


On 5/24/2016 9:02 PM, Steven D'Aprano wrote:
> On Wed, 25 May 2016 09:35 am, Gerald Britton wrote:
>
> For brevity, here's your package setup:
>
>
> testpkg/
> +-- __init__.py
> +-- testimport.py which runs "from testpkg.testimported import A"
> +-- testimported.py containing class A
>
> Your package layout is correct. But:

I have a similar setup, except with multiple files importing from 
imported file.  One way to make absolute imports within a package work, 
and how I do it, is to put the directory containing testpkg in a .pth 
file in the site-modules directory.  In particular, I have python.pth 
containing "F:/Python".  This effectively makes "Python" an extension of 
'site-packages', so when site-packages is searched for modules, so is 
Python.

-- 
Terry Jan Reedy

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


Thread

Question about imports and packages Gerald Britton <gerald.britton@gmail.com> - 2016-05-24 19:35 -0400
  Re: Question about imports and packages Steven D'Aprano <steve@pearwood.info> - 2016-05-25 11:02 +1000
    Re: Question about imports and packages Terry Reedy <tjreedy@udel.edu> - 2016-05-24 23:36 -0400

csiph-web