[Python-Dev] Re: Re: file() or open()?

Terry Reedy tjreedy at udel.edu
Sat Jul 10 07:05:59 CEST 2004


"orbitz" <orbitz at ezabel.com> wrote in message
news:40EC61DD.50704 at ezabel.com...
Terry Reedy wrote:

>>François Pinard" <pinard at iro.umontreal.ca> wrote in message
>>> perceived the introduction of `file()' as a nice cleanup in Python.

>> As a user, so did I.  I like the cosistency of using file along with
int,
>> tuple, list, dict, type, (and did I leave out something), and all user
>> classes as constructors of instances of themselves.

[top post moved down before responding to give better context]

>I considered more as the action being performed.  I'm opening something,

Are you, really?  I understand opening a door, gate, hinged lid, file
folder, gun stock,  clam, fist, or book.  All of these involve a hinge
motion, usually reversible.  Opening a drawer uses a reversible sliding
motion.  Opening a can, walnut, or geode involves an irreversible cut or
smash.  I do not see much analogy of any of these motions with the action
of open/type().

If you say that they all give access, I could just as well say that you are
unlocking, leasing, or learning something or acquiring a permission.

In my view, file/open() (in read mode) asks the interpreter to construct a
Python object that corresponds to and connects and gives access to the
external non-PyObject data (byte) stream indicated by the name/locator
string so that I may bring part or all of that data into the Python
dataspace as one or more Python objects (initially strings).  The
host-system specifics of the access mechanism is beyond the purview of
Python itself.

So, if you ignore the constructor analogy and want an action name, I think
proxy, connect, access, lease, or even setup might be better.  In short,
the action is

py_data_object = proxy(non_pyob_data_access_info)

Should socket.socket() have been socket.open because it 'opens' a
communication channel (in the process of creating a socket object)?  For
me, this analogy works at least as well as 'opening' a document (see
below).

>in this case a file.

Is it, really?  If one thinks in terms of the offices and desks, a file is
a container that keeps a series of related cards, papers, or documents in
order.  In this context, a series of bytes, usually represents and is
better called a paper or document.  People write documents and put them
into files.  But when documents are called 'files, files have to be called
something else, like 'directory' or 'folder' .

If by file one means a sequence or string of bytes in analogy with a file
of people, (also from the Latin filum == thread, as in filament), then
opening the file/sequence would seem to mean opening one or more spaces in
the sequence.  In chess and war, opening a file has the similar meaning of
removing enemy occupants from a series of spaces.

> And now I have an object which has been opened, I
> can perform operations on it, and when I'm done I close it.

I use the proxy to access non-Python data and then release the proxy.
What, if anything, the host system does upon release is outside the purview
of Python.

-----
In a previous post, Guido justified 'open' on the basis that applications
'open' 'files'.  However, in every such application I can think of at the
moment, 'open' means 'read the data and convert it to one of the
application's internal native formats, even if it was written in a
different format by another application.  In other words, app.open(path) ==
file(path).read().convert(filetype(path)).   Conversely, one never opens a
file before saveing a fresh new document; one just saves-as.  So Python's
open() is quite different from the app usage of 'open'.

Terry J. Reedy





More information about the Python-Dev mailing list