fileno function in file objects
Section 2.1.7.9 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? Regards, Martin
Section 2.1.7.9 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 file. 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/)
Incidentally... On Tue, 19 Sep 2000, Barry A. Warsaw wrote:
"GvR" == Guido van Rossum
writes: GvR> Note that this (and other, similar issues) is all because GvR> Python doesn't have a standard class hierarchy.
Or a formal interface mechanism.
Incidentally, jim/Zope is going forward with something like the interfaces strawman - the "scarecrow" - that jim proposed at IPC?7?. I don't know if a PEP would have made any sense for 2.x, so maybe it's just as well we haven't had time. In the meanwhile, DC will get a chance to get experience with and refine it... Anyway, for anyone that might be interested, i'm attaching a copy of python/lib/Interfaces/README.txt from a recent Zope2 checkout. I was pretty enthusiastic about it when jim originally presented the scarecrow, and on skimming it now it looks very cool. (I'm not getting it all on my quick peruse, and i suspect there's some contortions that wouldn't be necessary if it were happening more closely coupled with python development - but what jim sketches out is surprising sleek, regardless...) ken klm@digicool.com
participants (4)
-
bwarsaw@beopen.com
-
Guido van Rossum
-
Ken Manheimer
-
Martin von Loewis