fileno() not supported in Python 3.1

Nobody nobody at nowhere.invalid
Fri Nov 14 08:59:30 EST 2014


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).





More information about the Python-list mailing list