Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Nobody Newsgroups: comp.lang.python Subject: Re: fileno() not supported in Python 3.1 Date: Fri, 14 Nov 2014 13:59:30 +0000 Organization: A noiseless patient Spider Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="152d4dee6f95183c956ee6fa63d7e69f"; logging-data="29455"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+F5DRJ613jXmIglCmgKHfN" User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Cancel-Lock: sha1:DS/9QWCJ6r9f25bvquDQNj0GHlE= Xref: csiph.com comp.lang.python:80762 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).