isatty() for file-like objects: Implement or not?

H

HOWARD GOLDEN

The standard documentation for isatty() says:

"Return True if the file is connected to a tty(-like) device, else
False. Note: If a file-like object is not associated with a real file,
this method should not be implemented."

In his book, "Text Processing in Python," David Mertz says: "...
implementing it to always return 0 is probably a better approach."

My reaction is to agree with Mertz. I'd appreciate hearing from someone
why the standard documentation is the way it is. Is there some concept of
a file-like, non-real file that is to be distinguished using the
non-implementation of isatty()? If this is the intention, then my
suggestion is that this distinction is too indirectly expressed, and a
more direct approach would be easier for non-language lawyers to
understand. For example, there could be an attribute "unreal" (or,
contrarily, "real").

Howard B. Golden
 
N

Neal Norwitz

HOWARD said:
The standard documentation for isatty() says:

"Return True if the file is connected to a tty(-like) device, else
False. Note: If a file-like object is not associated with a real file,
this method should not be implemented."

In his book, "Text Processing in Python," David Mertz says: "...
implementing it to always return 0 is probably a better approach."

My reaction is to agree with Mertz.

I agree, I think the doc is wrong, e.g. StringIO has isatty() which
returns False. I think the doc was probably a thinko (or things have
changed) since Guido checked it in over 3 years ago.

It would be great if you can provide a patch or at least a bug report
on SourceForge.

Thanks,
n
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top