Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'python,': 0.01; 'python': 0.08; '(case': 0.09; 'relies': 0.09; 'underlying': 0.09; 'essentially': 0.10; 'library': 0.15; 'received:mindspring.com': 0.16; 'x-mailer:apple mail (2.1084)': 0.16; 'wrote:': 0.16; "wouldn't": 0.17; 'resolution': 0.21; "doesn't": 0.22; 'header:In- Reply-To:1': 0.22; 'cheers': 0.23; 'pm,': 0.24; 'aug': 0.24; 'guess': 0.26; 'developing': 0.26; 'import': 0.28; '27,': 0.29; 'consistently': 0.29; 'explicitly': 0.29; 'order.': 0.29; 'subject: .': 0.29; 'definition': 0.30; '"in': 0.30; 'relying': 0.30; 'varies': 0.30; 'list': 0.32; 'received:24': 0.32; 'agree': 0.33; 'probably': 0.33; 'to:addr:python-list': 0.33; 'it?': 0.33; 'rules': 0.34; '(as': 0.34; 'things': 0.34; 'directory.': 0.34; 'uses': 0.35; 'charset:us-ascii': 0.36; 'file': 0.36; 'using': 0.37; 'subject:: ': 0.39; 'returned': 0.39; 'header:Mime- Version:1': 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; 'your': 0.61; 'states': 0.61; 'header:Message-Id:1': 0.61; 'order': 0.62; 'guarantee': 0.66; 'order,': 0.73; 'habit': 0.84; 'received:69.73': 0.84; 'resolution,': 0.84 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1084) Subject: Re: Understanding .pth in site-packages From: Philip Semanchuk In-Reply-To: Date: Sat, 27 Aug 2011 23:01:11 -0400 Content-Transfer-Encoding: quoted-printable References: <31bef8dc-d804-454d-85c7-8de1663052a8@glegroupsg2000goo.googlegroups.com> <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> To: python-list list X-Mailer: Apple Mail (2.1084) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - deimos.nocdirect.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - semanchuk.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314500475 news.xs4all.nl 2468 [2001:888:2000:d::a6]:40895 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12327 On Aug 27, 2011, at 6:49 PM, Josh English wrote: > When I run: os.listdir('c:\Python27\lib\site-packages') I get the = contents in order, so the folders come before .pth files (as nothing = comes before something.) That's one definition of "in order". =3D) > I would guess Python is using os.listdir. Why wouldn't it? If you mean that Python uses os.listdir() during import resolution, then = yes I agree that's probable. And os.listdir() doesn't guarantee any = consistent order. In fact, the documentation explicitly states that the = list is returned in arbitrary order. Like a lot of things in Python, = os.listdir() probably relies on the underlying C library which varies = from system to system. (Case in point -- on my Mac, os.listdir() returns = things in the same order as the 'ls' command, which is case-sensitive = alphabetical, files & directories mixed -- different from Windows.) So if import relies on os.listdir(), then you're relying on arbitrary = resolution when you have a .pth file that shadows a site-packages = directory. Those rules will probably work consistently on your = particular system, you're developing a habit around what is essentially = an implementation quirk. =20 Cheers Philip=