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: 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: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=71.183.236.17; posting-account=jKjGDQoAAABKN2iauJtD3DV5oMZpXuQo References: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: 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 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: >=20 > > Hi, >=20 > > >=20 > > I have a package name collections and inside of my package I want to >=20 > > import the collections package from the standard library, but there >=20 > > is name conflicts. >=20 >=20 >=20 > Yes. I strongly advise against trying to do this. >=20 >=20 >=20 > > How do I import explicitly from the standard library? >=20 >=20 >=20 > Manipulate sys.path.=20 This is a common suggestion for working *around* the issue, but it has prob= lems of its own. In my opinion using sys.path is clunky - you may want to save an restore th= e value around use especially if the the place you are using it is not at t= he top level but in some inner less-exposed sub module. And make sure to re= store sys.path in the presence of exceptions getting thrown somewhere insid= e the import.=20 It is also a bit of a security nightmare. If something evil gets injected i= n 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 is= n'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 n= ot found inside the same directory as mypackage.foo, often I DON'T WANT Pyt= hon to helpfully go searching around other places for it which sys.path wil= l do. Instead what I probably want is Python to give me an error.=20 So again I come to import_relative, http://code.google.com/p/pyimport-relat= ive/. And again, I wish this package didn't have to exist. > If you don't know how, either read about sys.path=20 >=20 > (see index) or don't do it. >=20 >=20 >=20 > --=20 >=20 > Terry Jan Reedy