Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'package,': 0.03; 'importing': 0.04; 'case.': 0.05; 'paths': 0.05; 'python': 0.09; 'explanation': 0.09; 'friday,': 0.09; 'imported': 0.09; 'imports': 0.09; 'throw': 0.09; 'language,': 0.11; 'language': 0.14; 'clash': 0.16; "package's": 0.16; 'paths.': 0.16; 'renamed': 0.16; 'later': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'module,': 0.17; 'package.': 0.17; 'tries': 0.17; 'jan': 0.18; 'module': 0.19; 'math': 0.20; 'import': 0.21; '2.x': 0.22; 'explicit': 0.22; 'implicit': 0.22; 'header:In-Reply-To:1': 0.25; 'looks': 0.26; '(most': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'chris': 0.28; 'fri,': 0.30; 'relative': 0.30; 'gets': 0.32; 'johnson': 0.32; 'could': 0.32; '11,': 0.33; 'strict': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'exist': 0.35; 'path': 0.35; 'pm,': 0.35; 'received:209.85.220': 0.35; 'sometimes': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'modules': 0.36; 'enough': 0.36; 'does': 0.37; 'uses': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'containing': 0.61; 'first': 0.61; 'is.': 0.62; 'times': 0.63; 'skip:n 10': 0.63; 'decided': 0.65; 'choose': 0.65; '"look': 0.84; '2013': 0.84; ':).': 0.84; 'first?': 0.84; 'subject:Import': 0.84; 'to:name:python': 0.84; 'rick': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=ZITDATBYtlRZEw99qTYTUUuN4dxvdrA+9SrUPcCPDQA=; b=nsJIVZRRAfOgFr1qizhbGsBTlLUn2sPWxCG2RtZOVGm6hEVdnOyEtBp4db6BaogOG3 0sHCdUlp6I66mtHqDS+D4yBi5+bi3s+CmVWa+LaFQw2g45u9ZZNVgDFdGHEQQ8jwvcAE twZoR+QN4kKq1QuW503BhDku9xiNGVXiCq3+qRJmrM5lgwXyy5YPh6VAOC0AXBTPFn0E dUu2f5GseEacC4es5zGnlvP2auiRk8Fzu+8g6Xqh7ZLGwWEJeMmaYQIADRrxx2spMNUZ Danwj3UAkNvyqV/fpN6JfLQJ1KVsKNnxw0KwKQY0aWdnaShKE8vfyAN1CoMrlfQb+1oo tO2w== MIME-Version: 1.0 In-Reply-To: <2e407be7-2812-4c21-b91c-58e39b474bf7@googlegroups.com> References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> <2e407be7-2812-4c21-b91c-58e39b474bf7@googlegroups.com> From: Ian Kelly Date: Sat, 12 Jan 2013 00:36:43 -0700 Subject: Re: PyWart: Import resolution order To: Python Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357976236 news.xs4all.nl 6983 [2001:888:2000:d::a6]:53077 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36687 On Fri, Jan 11, 2013 at 10:28 PM, Rick Johnson wrote: > On Friday, January 11, 2013 12:30:27 AM UTC-6, Chris Angelico wrote: >> Why is it better to import from the current directory first? > > Opps. I was not explicit enough with my explanation :). I meant, "look in= the current directory FIRST when in a package". Since many times (most all= times) packages will contain many sub-modules that need to be imported int= o the package's main.py module, and sometimes these modules will have the s= ame name as a stdlib module, then looking in the package FIRST makes sense. And again, in Python 2.x this is already the case. When importing in a package, it tries to do a relative import before it even looks at sys.path. > I think if python where *strict* about full paths for non-builtins, then = we would be in a better place. And again, in Python 3, where implicit relative imports have been removed from the language, it already is strict about using full paths. You can still do relative imports, but you have to be explicit about them. > For instance you could create a package named "chris" and then have a mod= ule named math exist inside. Alternatively if you choose to be a non-profes= sional and create a math module without a containing package, python would = throw the module into the default "lib" package. The only way you could acc= ess your math module now would be by using the path "lib.math". What if I create a package named "math"? Does that also automatically get renamed to "lib.math"? How is it decided what package names are proper; is it just because it happens to clash with a stdlib name that the package gets magically renamed? What if I create a package, and then later a module with the same name happens to be added to the stdlib? My program that uses the package just breaks because it no longer imports the correct thing? > Damn i am full of good ideas! Your ideas might be better if you first spent some time gaining a better understanding of how the language works as is.