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


Groups > comp.lang.python > #41914

Re: import in Python3.3

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rocky@gnu.org>
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; 'explicitly': 0.05; 'ambiguity': 0.09; 'library?': 0.09; 'sub': 0.09; 'thrown': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'clunky': 0.16; 'collections': 0.16; 'exist.': 0.16; 'from:addr:gnu.org': 0.16; 'how,': 0.16; 'nightmare.': 0.16; 'reedy': 0.16; 'subject:import': 0.16; 'sys.path': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'bit': 0.19; 'trying': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'issue,': 0.24; 'library,': 0.24; 'own.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '(see': 0.26; 'somewhere': 0.26; 'gets': 0.27; 'header:In-Reply- To:1': 0.27; 'url:code': 0.29; 'strongly': 0.30; 'especially': 0.30; 'asked': 0.31; 'getting': 0.31; 'evil': 0.31; 'exceptions': 0.31; 'yes.': 0.31; 'this.': 0.32; 'probably': 0.32; 'common': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'impression': 0.36; 'module.': 0.36; "didn't": 0.36; 'hi,': 0.36; 'should': 0.36; 'error.': 0.37; 'searching': 0.37; 'level': 0.37; 'problems': 0.38; 'pm,': 0.38; 'von': 0.38; 'does': 0.39; 'sure': 0.39; 'either': 0.39; 'how': 0.40; 'read': 0.60; 'march': 0.61; 'save': 0.62; 'name': 0.63; 'places': 0.64; 'url:p': 0.64; 'series': 0.66; '26,': 0.68; 'wish': 0.70; 'restore': 0.78; '2013': 0.98
X-Received by 10.182.86.168 with SMTP id q8mr38465obz.3.1364312220237; Tue, 26 Mar 2013 08:37:00 -0700 (PDT)
Newsgroups comp.lang.python
Date Tue, 26 Mar 2013 08:37:00 -0700 (PDT)
In-Reply-To <mailman.3722.1364281502.2939.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=71.183.236.17; posting-account=jKjGDQoAAABKN2iauJtD3DV5oMZpXuQo
References <kio19e$5e2$1@ger.gmane.org> <mailman.3722.1364281502.2939.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 71.183.236.17
MIME-Version 1.0
Subject Re: import in Python3.3
From rocky <rocky@gnu.org>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Message-ID <mailman.3752.1364312224.2939.python-list@python.org> (permalink)
Lines 60
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364312224 news.xs4all.nl 6918 [2001:888:2000:d::a6]:51769
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:41914

Show key headers only | View raw


On Tuesday, March 26, 2013 3:04:44 AM UTC-4, Terry Reedy wrote:
> On 3/24/2013 7:12 PM, Fabian von Romberg wrote:
> 
> > Hi,
> 
> >
> 
> > I have a package name collections and inside of my package I want to
> 
> > import the collections package from the standard library, but there
> 
> > is name conflicts.
> 
> 
> 
> Yes. I strongly advise against trying to do this.
> 
> 
> 
> > How do I import explicitly from the standard library?
> 
> 
> 
> Manipulate sys.path. 

This is a common suggestion for working *around* the issue, but it has problems of its own.

In my opinion using sys.path is clunky - you may want to save an restore the value around use especially if the the place you are using it is not at the top level but in some inner less-exposed sub module. And make sure to restore sys.path in the presence of exceptions getting thrown somewhere inside the import. 

It is also a bit of a security nightmare. If something evil gets injected in there what does it effect and how would you know it? sys.path provides a series of directories where and evil masquerading Python program can linger.

And again, I get the impression that for the use case asked about, there isn't much ambiguity. If I am in mypackage.foo and I want to access mypackage.collections I should be able to say something like that without ambiguity or that much inference or directory searching. If mypackage.colletions is not found inside the same directory as mypackage.foo, often I DON'T WANT Python to helpfully go searching around other places for it which sys.path will do. Instead what I probably want is Python to give me an error. 

So again I come to import_relative, http://code.google.com/p/pyimport-relative/.  And again, I wish this package didn't have to exist.

> If you don't know how, either read about sys.path 
> 
> (see index) or don't do it.
> 
> 
> 
> -- 
> 
> Terry Jan Reedy

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


Thread

Re: import in Python3.3 Terry Reedy <tjreedy@udel.edu> - 2013-03-26 03:04 -0400
  Re: import in Python3.3 rocky <rocky@gnu.org> - 2013-03-26 08:37 -0700
    Re: import in Python3.3 Phil Connell <pconnell@gmail.com> - 2013-03-26 21:16 +0000
    Re: import in Python3.3 Rocky Bernstein <rocky@gnu.org> - 2013-03-26 18:24 -0400
    Re: import in Python3.3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-26 23:06 +0000
      Re: import in Python3.3 rocky <rocky@gnu.org> - 2013-03-26 17:33 -0700
  Re: import in Python3.3 rocky <rocky@gnu.org> - 2013-03-26 08:37 -0700

csiph-web