fileno() not supported in Python 3.1

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Nov 15 12:23:46 CET 2014


Ian Kelly wrote:

> On Fri, Nov 14, 2014 at 12:36 AM, Cameron Simpson <cs at zip.com.au> wrote:
>> On 13Nov2014 15:48, satishmlmlml at gmail.com <satishmlmlml at gmail.com>
>> wrote:
>>>
>>> import sys
>>> for stream in (sys.stdin, sys.stdout, sys.stderr):
>>>           print(stream.fileno())
>>>
>>>
>>> io.UnsupportedOperation: fileno
>>>
>>> Is there a workaround?
>>
>>
>> The first workaround that suggests itself it to use a more modern Python.
>> I've got 3.4.2 here, and it goes:
>>
>>    Python 3.4.2 (default, Nov  5 2014, 21:19:51)
>>    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.54)] on darwin
>>    Type "help", "copyright", "credits" or "license" for more information.
>>    >>> import sys
>>    >>> for stream in (sys.stdin, sys.stdout, sys.stderr):
>>    ...   print(stream.fileno())
>>    ...
>>    0
>>    1
>>    2
>>    >>>
>>
>> In short, in 3.4.2 it just works.
> 
> Why do you think the Python version has anything to do with it?

Because the OP states that he is using Python 3.1 (look at the subject line)
and it doesn't work in 3.1.

For what it is worth, I cannot confirm that alleged behaviour:

steve at orac:~$ python3.1 -c "import sys; print(sys.stdout.fileno())"
1


I suspect that the OP may be using an IDE which does something funny to
sys.stdout etc., or perhaps he has accidentally shadowed them. The OP
failed to copy and paste the actual traceback, so who knows what is
actually happening?



-- 
Steven




More information about the Python-list mailing list