File-like objects name attribute.

Terry Reedy tjreedy at udel.edu
Sun Jan 5 14:37:48 EST 2003


"Noah" <noah at noah.org> wrote in message
news:c9d82136.0301051014.7335bb8 at posting.google.com...
> I'm creating a file-like object. According to the current doc page:
>
>
http://www.python.org/doc/current/lib/bltin-file-objects.html#l2h-175
>     name
>         If the file object was created using open(), the name of the
file.
>         Otherwise, some string that indicates the source of the file
object,
>         of the form "<...>". This is a read-only attribute and may
not
>         be present on all file-like objects.
>
> What does the form "<...>" mean?

That the enclosed  string does *not* name a file.

> Does this mean I should include < > around  the  name for my
file-like object?
> For my purposes, I don't much care.   I just want to be complete.

.name is not used much and need not be present, but if you include it,
I would follow the convention.

> In my case, I am implementing a pure Python expect module.
> My file-like class spawns a child process and lets you talk to it
like a file.
> I want to have name represent the command and arguments of the child
process
> that was spawned. For exmaple, which of the following is more
correct:
>         name = "/bin/ls -la /etc"

This could be read as naming file 'etc' in subdirectory 'ls -la'
(legal on Windows, at least) of /bin.  Not quite what you intended
8<).

> or
>         name = "</bin/ls -la /etc>"

This is unambiguously *not* a file name!

Terry J. Reedy






More information about the Python-list mailing list