Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80728 > unrolled thread

fileno() not supported in Python 3.1

Started bysatishmlmlml@gmail.com
First post2014-11-13 15:48 -0800
Last post2014-11-16 16:29 +1100
Articles 11 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  fileno() not supported in Python 3.1 satishmlmlml@gmail.com - 2014-11-13 15:48 -0800
    Re: fileno() not supported in Python 3.1 Ben Finney <ben+python@benfinney.id.au> - 2014-11-14 10:57 +1100
      Re: fileno() not supported in Python 3.1 satishmlmlml@gmail.com - 2014-11-13 16:08 -0800
        Re: fileno() not supported in Python 3.1 Ben Finney <ben+python@benfinney.id.au> - 2014-11-14 13:52 +1100
    Re: fileno() not supported in Python 3.1 Cameron Simpson <cs@zip.com.au> - 2014-11-14 18:36 +1100
    Re: fileno() not supported in Python 3.1 Nobody <nobody@nowhere.invalid> - 2014-11-14 13:59 +0000
      Re: fileno() not supported in Python 3.1 Joel Goldstick <joel.goldstick@gmail.com> - 2014-11-14 09:09 -0500
    Re: fileno() not supported in Python 3.1 Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-14 09:51 -0700
      Re: fileno() not supported in Python 3.1 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-15 22:23 +1100
    Re: fileno() not supported in Python 3.1 Dan Stromberg <drsalists@gmail.com> - 2014-11-15 21:25 -0800
    Re: fileno() not supported in Python 3.1 Chris Angelico <rosuav@gmail.com> - 2014-11-16 16:29 +1100

#80728 — fileno() not supported in Python 3.1

Fromsatishmlmlml@gmail.com
Date2014-11-13 15:48 -0800
Subjectfileno() not supported in Python 3.1
Message-ID<bcc9a923-4a68-45b2-9854-a6f750e71ee7@googlegroups.com>
import sys 
for stream in (sys.stdin, sys.stdout, sys.stderr): 
           print(stream.fileno()) 


io.UnsupportedOperation: fileno 

Is there a workaround?

[toc] | [next] | [standalone]


#80730

FromBen Finney <ben+python@benfinney.id.au>
Date2014-11-14 10:57 +1100
Message-ID<mailman.15801.1415923079.18130.python-list@python.org>
In reply to#80728
satishmlmlml@gmail.com writes:

> Is there a workaround?

Please take the time to gather your thoughts, do not fire off a rapid
series of terse scattered questions.

What is it you're trying to do? What approach are you intending to take?

-- 
 \        “I was in Las Vegas, at the roulette table, having a furious |
  `\     argument over what I considered to be an odd number.” —Steven |
_o__)                                                           Wright |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#80732

Fromsatishmlmlml@gmail.com
Date2014-11-13 16:08 -0800
Message-ID<a3002f2b-c0a3-4e95-8f00-df84574e6b25@googlegroups.com>
In reply to#80730
How to get file descriptor number for the following:
sys.stdin
sys.stdout
sys.stderr

It is displaying io.UnsupportedOperation: fileno error

Kindly help.

[toc] | [prev] | [next] | [standalone]


#80738

FromBen Finney <ben+python@benfinney.id.au>
Date2014-11-14 13:52 +1100
Message-ID<mailman.15805.1415933545.18130.python-list@python.org>
In reply to#80732
satishmlmlml@gmail.com writes:

> How to get file descriptor number for the following:
> sys.stdin
> sys.stdout
> sys.stderr

Why do you need this? What are you intending to do?

-- 
 \       “Crime is contagious… if the government becomes a lawbreaker, |
  `\          it breeds contempt for the law.” —Justice Louis Brandeis |
_o__)                                                                  |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#80745

FromCameron Simpson <cs@zip.com.au>
Date2014-11-14 18:36 +1100
Message-ID<mailman.15812.1415950612.18130.python-list@python.org>
In reply to#80728
On 13Nov2014 15:48, satishmlmlml@gmail.com <satishmlmlml@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.

Cheers,
Cameron Simpson <cs@zip.com.au>

Chris Gascoyne, while struggling to program stuff on Microsoft Windows:
"I thought people said how bad it was just because they didn't like Microsoft."

[toc] | [prev] | [next] | [standalone]


#80762

FromNobody <nobody@nowhere.invalid>
Date2014-11-14 13:59 +0000
Message-ID<pan.2014.11.14.13.59.28.822000@nowhere.invalid>
In reply to#80728
On Thu, 13 Nov 2014 15:48:32 -0800, satishmlmlml wrote:

> import sys 
> for stream in (sys.stdin, sys.stdout, sys.stderr): 
>            print(stream.fileno()) 
> 
> 
> io.UnsupportedOperation: fileno 
> 
> Is there a workaround?

Try:
	sys.stdin.buffer.fileno()

or maybe

	sys.stdin.buffer.raw.fileno()

In Python 3.x, sys.stdin isn't actually a "file", it's a TextIOWrapper
around a BufferedReader around a file (io.FileIO).

TextIOWrapper is responsible for converting a stream of bytes to a stream
of (Unicode) characters. BufferedReader is responsible for buffering (like
C stdio).

[toc] | [prev] | [next] | [standalone]


#80764

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2014-11-14 09:09 -0500
Message-ID<mailman.15819.1415974187.18130.python-list@python.org>
In reply to#80762
On Fri, Nov 14, 2014 at 8:59 AM, Nobody <nobody@nowhere.invalid> wrote:
> On Thu, 13 Nov 2014 15:48:32 -0800, satishmlmlml wrote:
>
>> import sys
>> for stream in (sys.stdin, sys.stdout, sys.stderr):
>>            print(stream.fileno())
>>
>>
>> io.UnsupportedOperation: fileno
>>
>> Is there a workaround?
>
> Try:
>         sys.stdin.buffer.fileno()
>
> or maybe
>
>         sys.stdin.buffer.raw.fileno()
>
> In Python 3.x, sys.stdin isn't actually a "file", it's a TextIOWrapper
> around a BufferedReader around a file (io.FileIO).
>
> TextIOWrapper is responsible for converting a stream of bytes to a stream
> of (Unicode) characters. BufferedReader is responsible for buffering (like
> C stdio).
>
A little off topic, but why not upgrade to 3.4 if you are learning
python.  I run 2.7, but I've read that much has improved in the 3.x
series since 3.1
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#80774

FromIan Kelly <ian.g.kelly@gmail.com>
Date2014-11-14 09:51 -0700
Message-ID<mailman.15825.1415984229.18130.python-list@python.org>
In reply to#80728
On Fri, Nov 14, 2014 at 12:36 AM, Cameron Simpson <cs@zip.com.au> wrote:
> On 13Nov2014 15:48, satishmlmlml@gmail.com <satishmlmlml@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?

Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
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

Clearly, in 2.7.6 it also "just works".

[toc] | [prev] | [next] | [standalone]


#80819

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-11-15 22:23 +1100
Message-ID<546737c3$0$12977$c3e8da3$5496439d@news.astraweb.com>
In reply to#80774
Ian Kelly wrote:

> On Fri, Nov 14, 2014 at 12:36 AM, Cameron Simpson <cs@zip.com.au> wrote:
>> On 13Nov2014 15:48, satishmlmlml@gmail.com <satishmlmlml@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@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

[toc] | [prev] | [next] | [standalone]


#80854

FromDan Stromberg <drsalists@gmail.com>
Date2014-11-15 21:25 -0800
Message-ID<mailman.15868.1416115554.18130.python-list@python.org>
In reply to#80728
On Thu, Nov 13, 2014 at 3:48 PM,  <satishmlmlml@gmail.com> wrote:
> import sys
> for stream in (sys.stdin, sys.stdout, sys.stderr):
>            print(stream.fileno())
>
>
> io.UnsupportedOperation: fileno
>
> Is there a workaround?
> --
> https://mail.python.org/mailman/listinfo/python-list

Works for me, although it's a little different in Jython:
$ pythons --command 'import sys; print(sys.stdin.fileno())'
/usr/local/cpython-2.4/bin/python good 0
/usr/local/cpython-2.5/bin/python good 0
/usr/local/cpython-2.6/bin/python good 0
/usr/local/cpython-2.7/bin/python good 0
/usr/local/cpython-3.0/bin/python good 0
/usr/local/cpython-3.1/bin/python good 0
/usr/local/cpython-3.2/bin/python good 0
/usr/local/cpython-3.3/bin/python good 0
/usr/local/cpython-3.4/bin/python good 0
/usr/local/jython-2.7b3/bin/jython good org.python.core.io.StreamIO@170ed6ab
/usr/local/pypy-2.3.1/bin/pypy good 0
/usr/local/pypy-2.4.0/bin/pypy good 0
/usr/local/pypy3-2.3.1/bin/pypy good 0
/usr/local/pypy3-2.4.0/bin/pypy good 0

[toc] | [prev] | [next] | [standalone]


#80855

FromChris Angelico <rosuav@gmail.com>
Date2014-11-16 16:29 +1100
Message-ID<mailman.15869.1416115794.18130.python-list@python.org>
In reply to#80728
On Sun, Nov 16, 2014 at 4:25 PM, Dan Stromberg <drsalists@gmail.com> wrote:
> Works for me, although it's a little different in Jython:
> $ pythons --command 'import sys; print(sys.stdin.fileno())'
> /usr/local/jython-2.7b3/bin/jython good org.python.core.io.StreamIO@170ed6ab

Huh, that is curious. According to its CPython docstring, it's
supposed to return an integer (no idea if that's standardized)... but
I guess if os.read() takes that StreamIO object, then it'll do as
well.

ChrisA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web