Windows/Cygwin/MacOSX import (was RE: python-dev summary, 2001-02-01 - 2001-02-15)

Tim Peters tim.one at home.com
Fri Feb 16 23:32:51 EST 2001


[Terry Reedy]
> One of the hassles with Win9X is that Windows Explorer displays,
> I believe, some files differently from how they are stored.

This depends on the setting of Explorer's

    View -> Folder Options ... -> View -> Allow all uppercase names

option.  It that's on, file names are shown as stored.  But it's off by
default.  Then an ALLCAPS name is shown as Allcaps (i.e., first letter
uppercase, all the rest lowercase), while other names are shown as stored.

This has no effect on any Python file in the distribution, though, because
they all end with (lowercase) ".py", so they never meet the criteria "Allow
all uppercase names" is looking for.

> So I have sometimes had trouble opening files.

I don't understand that, as open() is case-insensitive on Windows.  Perhaps
you're thinking of Explorer's "Hide file extensions for known file types"
option?  *That* could give you trouble when opening files -- but isn't
relevant to Python imports.

> (Did the ALLCAPS exception apply here too?)

Always to import, never to anything else.  For each of the four file names

    ab
    Ab
    aB
    AB

on Windows, every one of the following works fine to open it:

    open("ab")
    open("Ab")
    open("aB")
    open("AB")

Python doesn't do anything special to make that happen -- that's just the
way the Windows system libraries work.

> As long as os.listdir('.') displays filenames in a form acceptible
> to import and open(), I should be ok.

You're forcing me to be careful here <0.9 wink>:  the names returned by
listdir('.') work fine for open() as-is on Windows, but also would if you
ran them through string.upper() first, or through string.lower() first, or
if you picked a case at random for each character in the name.

But the names will rarely work in an import statement (and don't today
either), because e.g.

    import random.py

will only work if you happen to have a *package* named random containing a
*module* named py (so is in a file named py.py).  In normal use, you have to
strip the extension off the filename before importing it.

Beyond that, yes, listdir() returns names using the case choices with which
they were created.  And Explorer options don't affect what listdir() does.





More information about the Python-list mailing list