[Python-Dev] RE: Windows IO

Tim Peters tim.one@comcast.net
Mon, 17 Mar 2003 17:09:54 -0500

[David LeBlanc]
> I don't have the capability to open an SF bug report.

It's not restricted -- anyone can open a bug report.  You need a web browser
and an internet connection, of course.

> "isatty" is not documented at all under the Global Modules "sys" entry for
> Python 2.2.1 documentation

No, but why would it be?  I gave you a link to the current docs before:


Go there and search down for isatty.  In 2.2.1, the link is this instead:


> (sorry, I thought "PythonDoc" was a recognized
> name). The following doesn't work:
> J:\>python
> Python 2.2.1 (#34, Jul 16 2002, 16:25:42) [MSC 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> stdout.isatty()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> NameError: name 'stdout' is not defined

I showed concrete examples in the last msg.  stdout lives in sys, as was
shown there:

>>> import sys
>>> sys.stdout.isatty()

That's in 2.3.  I don't have 2.2.1.  Here's under 2.0:

>>> import sys
>>> sys.stdout.isatty()

> >>> isatty(stdout)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> NameError: name 'isatty' is not defined
> >>> isatty(__stdout__)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> NameError: name 'isatty' is not defined
> >>> import os
> >>> os.stdout.isatty()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'module' object has no attribute 'stdout'
> >>>

Please read the docs -- there's no reason to expect any of those to work.

> Is isatty a built-in,


> a function of os only available on Unix,

No, although os.isatty exists on some platforms.  fileobject.isatty() exists
on all platforms.

> or a function of sys available on all platforms?

It's not in sys on any platform.

> It appears to be a function in the sys module and so the doc for it should
> go there?

Nope, isatty() is never in sys.  It's primarily a *method* on file objects,
as all the examples I've given have used.  sys.stdin and sys.stdout are file

> Under the "os" entry it's:
> "isatty(fd)
> Return 1 if the file descriptor fd is open and connected to a tty(-like)
> device, else 0. Availability: Unix. "
> I don't see how to create a file() that is connected to stdout without
> importing sys...? Is there a way? If there is not, than file.isatty() is
> moot.

Sorry, I don't understand the question.

> So, really, what is the meaning of "64" as the return from
> sys.stdout.isatty()?

Before Python 2.3, it's simply the value Microsoft's isatty() function
returned.  Python 2.3 translates it to a bool.  Microsoft's docs say:

    _isatty returns a nonzero value handle is associated with a character
    device. Otherwise, _isatty returns 0.

The grammar errors are copied verbatim from their docs, BTW -- telling me
that didn't make sense won't help you <wink>.