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


Groups > comp.lang.python > #12327

Re: Understanding .pth in site-packages

Subject Re: Understanding .pth in site-packages
From Philip Semanchuk <philip@semanchuk.com>
Date 2011-08-27 23:01 -0400
References (2 earlier) <2763f908-2feb-4d2f-b422-433de26b2868@glegroupsg2000goo.googlegroups.com> <B593279B-2238-48B9-A797-E92B022B6F76@semanchuk.com> <j3bj7t$798$1@dough.gmane.org> <mailman.481.1314476912.27778.python-list@python.org> <c6d1898c-cb20-4dac-9614-95f23d4a2c42@glegroupsg2000goo.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.499.1314500475.27778.python-list@python.org> (permalink)

Show all headers | View raw


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". =)


> 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.  

Cheers
Philip

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


Thread

Understanding .pth in site-packages Josh English <Joshua.R.English@gmail.com> - 2011-08-27 09:56 -0700
  Re: Understanding .pth in site-packages Philip Semanchuk <philip@semanchuk.com> - 2011-08-27 13:18 -0400
    Re: Understanding .pth in site-packages Josh English <Joshua.R.English@gmail.com> - 2011-08-27 10:57 -0700
      Re: Understanding .pth in site-packages "OKB (not okblacke)" <brenNOSPAMbarn@NObrenSPAMbarn.net> - 2011-08-27 19:45 +0000
        Re: Understanding .pth in site-packages Josh English <Joshua.R.English@gmail.com> - 2011-08-27 15:39 -0700
          Re: Understanding .pth in site-packages "OKB (not okblacke)" <brenNOSPAMbarn@NObrenSPAMbarn.net> - 2011-08-28 05:20 +0000
    Re: Understanding .pth in site-packages Josh English <Joshua.R.English@gmail.com> - 2011-08-27 10:57 -0700
      Re: Understanding .pth in site-packages Philip Semanchuk <philip@semanchuk.com> - 2011-08-27 14:07 -0400
      Re: Understanding .pth in site-packages Terry Reedy <tjreedy@udel.edu> - 2011-08-27 16:14 -0400
      Re: Understanding .pth in site-packages Philip Semanchuk <philip@semanchuk.com> - 2011-08-27 16:28 -0400
        Re: Understanding .pth in site-packages Josh English <Joshua.R.English@gmail.com> - 2011-08-27 15:49 -0700
        Re: Understanding .pth in site-packages Josh English <Joshua.R.English@gmail.com> - 2011-08-27 15:49 -0700
          Re: Understanding .pth in site-packages Philip Semanchuk <philip@semanchuk.com> - 2011-08-27 23:01 -0400
      Re: Understanding .pth in site-packages Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-08-27 13:53 -0700
        Re: Understanding .pth in site-packages Josh English <Joshua.R.English@gmail.com> - 2011-08-27 15:41 -0700
        Re: Understanding .pth in site-packages Josh English <Joshua.R.English@gmail.com> - 2011-08-27 15:41 -0700
          Re: Understanding .pth in site-packages Stephen Hansen <me+list/python@ixokai.io> - 2011-08-27 16:44 -0700
  Re: Understanding .pth in site-packages Peter Otten <__peter__@web.de> - 2011-08-27 19:29 +0200
  Re: Understanding .pth in site-packages Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-08-27 13:53 -0700

csiph-web