[Python-Dev] fileno function in file objects

Guido van Rossum guido@beopen.com
Tue, 19 Sep 2000 09:33:02 -0500

> Section of the library reference explains that file objects
> support a fileno method. Is that a mandatory operation on file-like
> objects (e.g. StringIO)? If so, how should it be implemented? If not,
> shouldn't the documentation declare it optional?
> The same question for documented attributes: closed, mode, name,
> softspace: need file-like objects to support them?

fileno() (and isatty()) is OS specific and only works if there *is* an
underlying file number.  It should not be implemented (not even as
raising an exception) if it isn't there.

Support for softspace is needed when you expect to be printing to a

The others are implementation details of the built-in file object, but
would be nice to have if they can be implemented; code that requires
them is not fully supportive of file-like objects.

Note that this (and other, similar issues) is all because Python
doesn't have a standard class hierarchy.  I expect that we'll fix all
this in Python 3000.  Until then, I guess we have to muddle forth...

BTW, did you check in test cases for all the methods you fixed?

--Guido van Rossum (home page: http://www.pythonlabs.com/~guido/)