[I18n-sig] Modified open() builtin (Re: Python Character Model)

Barry A. Warsaw barry@digicool.com
Mon, 12 Feb 2001 09:14:23 -0500


>>>>> "PP" == Paul Prescod <paulp@ActiveState.com> writes:

    PP> file = open("/etc/passwd", "r", "ASCII")

    PP> Surely that is not such a terrible burden in the interests of
    PP> making the world a little bit less xenophobic! Once you do
    PP> that, everything else "just works" and when your program
    PP> encounters data it can't handle in a text file it will crash
    PP> in a predictable way at a logical point (the read function)
    PP> instead of in an unpredictable way at an illogical point (some
    PP> random string coercion or API call).

Requiring the encoding imposes too much burden on the newbie learning
the language, IMHO.  It seems obvious that if you're going to open
something, you've got to specify what your opening (i.e. open() makes
no sense without the filename parameter).  I think you can easily
explain the difference between opening for reading and opening for
writing, although the myriad other mode options are pushing it
(e.g. the difference b/w r+, w+, and a+ are quite subtle and not
described sufficiently).

Now to require the encoding either forces you to ask the user to trust
you ("most of you will just want `ascii' for the encoding parameter,
don't worry about what that means"), or to go into /some/ explanation
of what encodings are, what the possible legal values are, what the
difference between "ascii" and "raw" are and when you want to use
them, what can happen if you misspell an encoding, how to guess the
encoding of the file you're about to open, What can happen if you
guess incorrectly, etc. etc.

If you care about file encodings, you've got to learn all that
anyway.  Fine, but that's a heavy burden to place on a new convert.
I'm convinced Guido felt that open() would be used very early on in a
newbie's experience and wanted to make it as simple as possible.
That's why it's a built-in.

Other messages in this thread seem to agree that /if/ open() were to
grow an encoding argument, it should be optional.

-Barry