File-like objects name attribute.
tjreedy at udel.edu
Sun Jan 5 20:37:48 CET 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:
> If the file object was created using open(), the name of the
> Otherwise, some string that indicates the source of the file
> of the form "<...>". This is a read-only attribute and may
> 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
> 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
> that was spawned. For exmaple, which of the following is more
> 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
> name = "</bin/ls -la /etc>"
This is unambiguously *not* a file name!
Terry J. Reedy
More information about the Python-list