Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsfeed.freenet.ag!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'package,': 0.03; 'paths': 0.05; 'builtin': 0.07; 'executable': 0.07; 'prefix': 0.07; 'python': 0.09; 'explanation': 0.09; 'friday,': 0.09; 'imported': 0.09; 'modules.': 0.09; 'path.': 0.09; 'throw': 0.09; 'to:addr:comp.lang.python': 0.09; 'toplevel': 0.09; 'unexpected': 0.09; 'unix,': 0.09; 'cc:addr:python-list': 0.10; 'properly': 0.15; '(meaning': 0.16; 'clashes': 0.16; 'cleaner': 0.16; 'demonstrable': 0.16; 'modules,': 0.16; 'nest': 0.16; "package's": 0.16; 'wrote:': 0.17; 'instance': 0.17; 'module,': 0.17; 'package.': 0.17; 'windows': 0.19; 'module': 0.19; 'math': 0.20; 'packaging': 0.20; 'import': 0.21; 'explicit': 0.22; 'fine,': 0.22; 'latter': 0.22; 'cc:2**0': 0.23; 'programming': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'order.': 0.27; 'realize': 0.27; 'module.': 0.27; 'options': 0.27; 'chris': 0.28; 'wrap': 0.29; 'maybe': 0.29; 'related': 0.30; 'resolution': 0.30; 'code': 0.31; 'could': 0.32; '11,': 0.33; 'likely': 0.33; 'received:google.com': 0.34; 'built-in': 0.35; 'exist': 0.35; 'path': 0.35; 'doing': 0.35; 'sometimes': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'modules': 0.36; 'programmers': 0.36; 'anything': 0.36; 'problems': 0.36; 'enough': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'list,': 0.39; 'little': 0.39; 'where': 0.40; 'think': 0.40; 'your': 0.60; 'real': 0.61; 'containing': 0.61; 'first': 0.61; 'stay': 0.61; 'back': 0.62; 'time,': 0.62; 'policy': 0.62; 'solve': 0.62; 'world': 0.63; 'times': 0.63; 'skip:n 10': 0.63; 'more': 0.63; 'choose': 0.65; 'soon.': 0.73; 'power': 0.74; '"look': 0.84; '2013': 0.84; ':).': 0.84; 'first?': 0.84; 'holes': 0.84; 'packaged': 0.84; 'subject:Import': 0.84; 'yet?': 0.84; 'below!': 0.91; 'rick': 0.91; 'refuse': 0.93; 'wait,': 0.93; 'hand,': 0.97 Newsgroups: comp.lang.python Date: Fri, 11 Jan 2013 21:28:49 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=70.196.131.158; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj References: <88bab977-ca49-487a-8fba-7d3350266d8d@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 70.196.131.158 MIME-Version: 1.0 Subject: Re: PyWart: Import resolution order From: Rick Johnson 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: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1357969142 news.xs4all.nl 6968 [2001:888:2000:d::a6]:47524 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36675 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 t= he current directory FIRST when in a package". Since many times (most all t= imes) packages will contain many sub-modules that need to be imported into = the package's main.py module, and sometimes these modules will have the sam= e name as a stdlib module, then looking in the package FIRST makes sense. But the real solution is not to change the default resolution order. The re= al solution is to wrap all builtin modules into a package and use full path= s to access every module. But wait, i have an even better idea... read belo= w! > Windows > has that policy for executable commands; Unix, on the other hand, > requires that you put an explicit path for anything that isn't in the > standard search path. Which of these options is the more likely to > produce security holes and/or unexpected behaviour? I prefer the latter of course :).=20 I think if python where *strict* about full paths for non-builtins, then we= would be in a better place. But there is an even better solution! Force al= l python users to wrap THEIR modules in a toplevel package. Maybe even crea= te the package for them. YES!. Call it "lib". Any "naked" modules (meaning = modules that are not in a package) would have to be accessed starting from= "lib". Of course professionals like you and i are already using packages t= o properly nest out modules, but the newbie's won't realize the power of pa= ckaging modules for some time, so create the default "lib" package for them= . For instance you could create a package named "chris" and then have a modul= e named math exist inside. Alternatively if you choose to be a non-professi= onal and create a math module without a containing package, python would th= row the module into the default "lib" package. The only way you could acces= s your math module now would be by using the path "lib.math".=20 So the conclusion is: * We encourage python programmers to use packages so they avoid any name c= lashes with built-in modules.=20 =20 * if they refuse fine, any "naked" modules they create will be packaged in= a default package (call it "lib", "userlib", or whatever) and will require= them to prefix the module name with "lib." -- or "lib:" if i get my way! =20 By doing this we solve the many problems related to module name resolution = orders and we create cleaner code bases. Damn i am full of good ideas! > Welcome back to the list, Rick. Got any demonstrable code > for Python 4000 yet? I am working on it. Stay tuned. Rick is going to rock your little programmi= ng world /very/ soon.